fix: error handling in fs routes (#2474)
Ran into an issue where we weren't responding with the correct status code and passed response headers. This was a bit of a rabbit hole and it was caused by us wrapping to more error handling middlewares than necessary.
This commit is contained in:
@@ -156,6 +156,8 @@ export async function fsRoutes<State>(
|
||||
const stack: InternalRoute<State>[] = [];
|
||||
let hasApp = false;
|
||||
|
||||
const specialPaths = new Set<string>();
|
||||
|
||||
for (let i = 0; i < routeModules.length; i++) {
|
||||
const routeMod = routeModules[i];
|
||||
const normalized = routeMod.path;
|
||||
@@ -246,10 +248,15 @@ export async function fsRoutes<State>(
|
||||
}
|
||||
let parent = mod.path.slice(0, -"_error".length);
|
||||
parent = parent === "/" ? "*" : parent + "*";
|
||||
app.all(
|
||||
parent,
|
||||
errorMiddleware(errorComponents, handler),
|
||||
);
|
||||
|
||||
// Add error route as it's own route
|
||||
if (!specialPaths.has(mod.path)) {
|
||||
specialPaths.add(mod.path);
|
||||
app.all(
|
||||
parent,
|
||||
errorMiddleware(errorComponents, handler),
|
||||
);
|
||||
}
|
||||
middlewares.push(errorMiddleware(errorComponents, handler));
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user