Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add rawError option #44

Closed
wants to merge 2 commits into from
Closed

Feature: Add rawError option #44

wants to merge 2 commits into from

Conversation

rafoss
Copy link

@rafoss rafoss commented Aug 10, 2020

Description

Introduces a new boolean option rawError to GuardProvider and GuardedRoute which makes them pass through errors thrown by GuardFunctions unaltered.

What this does

It alters the behaviour of error handling as seen here to use the raw thrown value instead of trying to access the message property on it and returning "Not found." as a fallback.

Use case

Custom errors such as extended Error objects which specify further details or entirely custom types thrown by GuardFunctions can now be accessed on the error prop of the Error page component.
A GuardFunction could for instance throw 403; to indicate HTTP status code 403 Forbidden to the Error page so it can conditionally render a forbidden page. This way it's not necessary to supply different error props per GuardedRoute you want to display different errors for.

Sidenote

In my opinion, a breaking change to supply the raw error by default would be nicer, but may cause more problems than it solves, so I've submitted this PR as a backwards compatible solution.

How to test

No test changes were made.

@joshpensky joshpensky added help wanted Extra attention is needed needs review and removed help wanted Extra attention is needed labels Aug 28, 2020
@joshpensky
Copy link
Member

Hey @rafoss! Thank you so much for submitting this PR (and apologies for taking so long to review it)!

We agree with your sentiment of replacing the default error prop with the raw error object and are hoping to move forward with this idea as a breaking change! With #84, we're planning to land this change in 1.1.0 (after some non-breaking changes make it into 1.0.3)

Thank you again for your contributions! 🙌

@joshpensky joshpensky closed this Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants