Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Introduces a new boolean option
rawError
toGuardProvider
andGuardedRoute
which makes them pass through errors thrown byGuardFunctions
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 theerror
prop of the Error page component.A
GuardFunction
could for instancethrow 403;
to indicate HTTP status code403 Forbidden
to the Error page so it can conditionally render a forbidden page. This way it's not necessary to supply differenterror
props perGuardedRoute
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.