-
Hi folks... I'm currently struggling a bit with Error handling for a route that is only supposed to "redirect". I read the docs but I couldn't get the pieces together to solve this puzzle so I decide to come out to ask for help. ProblemConsider the following route structure:
// routes/project/index.tsx
export async function loader() {
try {
const latestProjectId = await getNewestProjectId();
return redirect(`/project/${latestProjectId}`);
} catch (error) {
console.log("Something went wrong :(");
throw error;
}
} To cover possible errors on this route, I add both // routes/project/index.tsx
export function ErrorBoundary() {
return <h1>ErrorBoundary ("app/routes/project/index.tsx")</h1>;
}
export function CatchBoundary() {
return <h1>oh no Catch</h1>;
} My struggle is that if the Client-side navigation
Accessing directlyHere I just access the endpoint GotchaAs far I understood, when I hit Questions
Reproducible examplerepository |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
The main issue here is that in projects.tsx, you commented out the When you navigate via So in this case, Remix is working as designed, although a little confusing. |
Beta Was this translation helpful? Give feedback.
-
I use Remix to server api resource routes, in this case imaging api endpoints called via postman, so there is no UI component. I was expecting I can handle errors using Instead I get an generic error:
I am not even sure how to expand I think it's similar to question asked by @ZeldOcarina |
Beta Was this translation helpful? Give feedback.
-
Would still love some guidance on this! How do we handle resource routes returning errors? I found this blog post about using fetchers, but it would nice to have something a little more built-in. https://jankraus.net/2024/09/06/downloading-files-in-remix-with-usefetcher-hook/ |
Beta Was this translation helpful? Give feedback.
The main issue here is that in projects.tsx, you commented out the
default export
(the UI component). When you make a full request (not via client link), Remix notices there is no default export and treats it as a resource route. Remix returns the raw response to the client for resource requests. If there's an error, it simply returns a status 500 Unexpected Server Error. Since resource routes are not intended to be part of the UI, they don't get wrapped in<ErrorBoundary>
.When you navigate via
<Link>
, Remix will make the client side fetch request and appends the_data=route_id
search param. Remix then treats this as a data request and calls the loader. If there's an error, it will retur…