winterspec
Version:
Write Winter-CG compatible routes with filesystem routing and tons of features
19 lines (18 loc) • 706 B
JavaScript
export const withUnhandledExceptionHandling = async (req, ctx, next) => {
try {
return await next(req, ctx);
}
catch (e) {
const logger = ctx.logger ?? console;
if ("_isHttpException" in e) {
logger.warn("Caught unhandled HTTP exception thrown by WinterSpec provided middleware. Consider adding createWithDefaultExceptionHandling middleware to your global or route spec.");
}
else {
logger.warn("Caught unknown unhandled exception; consider adding a exception handling middleware to your global or route spec.");
}
logger.error(e);
return new Response(null, {
status: 500,
});
}
};