-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa5a7a8
commit cb8c1ba
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: isRouteErrorResponse | ||
--- | ||
|
||
# `isRouteErrorResponse` | ||
|
||
<docs-info>This is just a re-export of the React Router [`isRouteErrorResponse`][rr-is-route-error-response] utility.</docs-info> | ||
|
||
When a response is thrown from an action or loader, it will be unwrapped into an `ErrorResponse` so that your component doesn't have to deal with the complexity of unwrapping it (which would require React state and effects to deal with the promise returned from `res.json()`) | ||
|
||
```jsx | ||
import { json } from "@remix-run/node"; | ||
|
||
export function action() { | ||
throw json( | ||
{ message: "email is required" }, | ||
{ status: 400, statusText: "Bad Request" } | ||
); | ||
} | ||
|
||
export function ErrorBoundary() { | ||
const error = useRouteError(); | ||
if (isRouteErrorResponse(error)) { | ||
error.status; // 400 | ||
error.statusText; // Bad Request | ||
error.data; // { "message: "email is required" } | ||
} | ||
} | ||
``` | ||
|
||
<docs-info>If the user visits a route that does not match any routes in the app, Remix itself will throw a 404 response.</docs-info> | ||
|
||
[rr-is-route-error-response]: https://reactrouter.com/en/main/utils/is-route-error-response |