-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
[Docs]: It is unclear how to return errors from server-side Resource Routes #12888
Comments
I'm up for doing a PR to update the docs for this, I just need a little direction from somebody closer to the project on what the recommended pattern here is, then I can write it up. |
I see now that the Remix In entry.server it says:
Some other breadcrumbs from the Remix dev docs:
So it seems that:
Unfortunately, I haven't been able to crack what the hueristic is for when should you |
I tested what happens when you throw data in a Resource Route. As for which one to use, I think return is a good choice if you want to display the error response on the page, and throw works well if you want to display the Error Boundary. |
Additionally, even if you follow the documentation's suggestion and use |
Describe what's incorrect/missing in the documentation
The doc for Resource Routes encourages you to
return
aResponse.json
from a REST/resource endpoint, but only shows the happy path.If you
return
aResponse.json
with{ status: 500 }
, it sort of works but error reporting doesn't work – that is, the centralhandleError
inentry.server.tsx
doesn't fire.This, plus the fact Remix tended towards having you
throw
errors, makes it seem like you are not supposed toreturn
an error from a resource route.However, the Error Boundaries doc says:
And the Status Codes doc advises you to "Set status codes from loaders and actions with
data
.", with this examplereturn
ing a 4xx error inside anaction
:These make it seem like you are supposed to
return
an error, but meanwhile, there's also similar but different format in the Error Boundaries doc showing athrow
under the title Throw data in loaders/actions:Since the above is in the Error Boundaries doc, it's not clear this is applicable to resource routes, since I believe resource routes do not render within an Error Boundary.
So, in short, can we get clear & consistent documentation on how we're meant to return a 4xx or 5xx error from an resource route's
action
?The text was updated successfully, but these errors were encountered: