-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Open
Labels
Description
Describe what's incorrect/missing in the documentation
In middleware error handling section, it demonstrates that we could re-throw error to let react router handle it.
However, in a basic example like Error: You made a GET request to "/" but did not provide a
loader for route...
, the error after re-throw becomes [object, object]
, because it becomes an route error response object, and we are throwing it without handling the error.
export const unstable_middleware: Route.unstable_MiddlewareFunction[] = [
async ({ request, context, params }, next) => {
const { searchParams } = new URL(request.url);
const callNext = searchParams.has("next");
try {
callNext && (await next());
} catch (error) {
if (isRouteErrorResponse(error)) {
// The error is extracted in middleware. How to re-throw as if no middleware was applied?
console.log("Middleware route error response", error);
}
throw error;
}
},
];
- If this is expected behavior of the middleware, maybe add a
isRouteErrorResponse(error)
calling to make it clearer. - Or we need a way to reconstruct a route error response.
Reproduction: gjc14/middleware-error-handling