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

[Docs]: It is unclear how to return errors from server-side Resource Routes #12888

Open
apike opened this issue Jan 29, 2025 · 0 comments
Open
Labels

Comments

@apike
Copy link

apike commented Jan 29, 2025

Describe what's incorrect/missing in the documentation

The doc for Resource Routes encourages you to return a Response.json from a REST/resource endpoint, but only shows the happy path.

If you return a Response.json with { status: 500 }, it sort of works but error reporting doesn't work – that is, the central handleError in entry.server.tsx doesn't fire.

This, plus the fact Remix tended towards having you throw errors, makes it seem like you are not supposed to return an error from a resource route.

However, the Error Boundaries doc says:

It's not recommended to intentionally throw errors to force the error boundary to render as a means of control flow. ... This is not just for loaders, but for all route module APIs: loaders, actions, components, headers, links, and meta.

And the Status Codes doc advises you to "Set status codes from loaders and actions with data.", with this example returning a 4xx error inside an action:

    return data(
      { message: "Invalid title" },
      { status: 400 }
    );

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 a throw under the title Throw data in loaders/actions:

    throw data("Record Not Found", { status: 404 });

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?

@apike apike added the docs label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant