fix: Use custom 500 page for *all* handlers if present (#1362)

This commit is contained in:
Kamil Ogórek
2023-06-27 11:05:05 +02:00
committed by GitHub
parent ee3e4a1145
commit aff31c0f15
8 changed files with 108 additions and 1 deletions
+14 -1
View File
@@ -440,7 +440,20 @@ export class ServerContext {
const middlewareCtx: MiddlewareHandlerContext = {
next() {
const handler = handlers.shift()!;
return Promise.resolve(handler());
try {
// As the `handler` can be either sync or async, depending on the user's code,
// the current shape of our wrapper, that is `() => handler(req, middlewareCtx)`,
// doesn't guarantee that all possible errors will be captured.
// `Promise.resolve` accept the value that should be returned to the promise
// chain, however, if that value is produced by the external function call,
// the possible `Error`, will *not* be caught by any `.catch()` attached to that chain.
// Because of that, we need to make sure that the produced value is pushed
// through the pipeline only if function was called successfully, and handle
// the error case manually, by returning the `Error` as rejected promise.
return Promise.resolve(handler());
} catch (e) {
return Promise.reject(e);
}
},
...connInfo,
state: {},