使用中介軟體處理錯誤
app.use(async (ctx, next) => {
try {
await next() // attempt to invoke the next middleware downstream
} catch (err) {
handleError(err, ctx) // define your own error handling function
}
})
app.use(async (ctx, next) => {
try {
await next() // attempt to invoke the next middleware downstream
} catch (err) {
handleError(err, ctx) // define your own error handling function
}
})