Replies: 1 comment 3 replies
-
Remix supports throwing anything because at the end in JS you can throw anything, Remix also supports throwing responses, if you throw a redirect from a loader or action the redirect will be followed, if you throw a json response that data will be returned from useRouteError and the response headers and status will be used in the actual response the browser receives. If you throw anything else Remix will give you that from useRouteError. Then in your component you can do what you want to ensure the value is what you expect, maybe cast the type to be Error or validate it. let routeError = useRouteError()
if (routeError instanceof Error) {
// use routeError.message here
}
if (typeof routeError === "string") {
// use just routeError here
}
// more cases |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
At first I assumed it was a misunderstanding when reading the tutorial, but then the error boundary example throws like this too, complete with arbitrary payloads, in a typescript file, with no signature declarations.
Error handling is all over the place too, at one part it boldly assumes the return of
useRouteError()
is of typeError
with no validation whatsoever. But in another it does go through the process of validating it with library-specific logic.Take note the MDN article specifically states that the thrown object should be
Error
s or subclasses of it:All these questions popped up because I wanted to create a form which shows errors right inside it on submit if it fails for whatever reason. I assumed with all the under the hood magic react router would have this ability out of the box and I could adapt this monstrosity with no problems, but it doesn't look to be the case judging by documentation.
Beta Was this translation helpful? Give feedback.
All reactions