wildebeest/backend/src/middleware/error.ts

12 wiersze
358 B
TypeScript

/**
* A Pages middleware function that logs errors to the console and responds with 500 errors and stack-traces.
*/
export async function errorHandling(context: EventContext<unknown, any, any>) {
try {
return await context.next()
} catch (err: any) {
console.log(err.stack)
return new Response(`${err.message}\n${err.stack}`, { status: 500 })
}
}