Skip to content

Commit

Permalink
fix: handle thrown errors by each layer
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 20, 2021
1 parent 1441784 commit 62fd25a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ export function createHandle (stack: Stack): PHandle {
if (layer.match && !layer.match(req.url as string, req)) {
continue
}
const val = await layer.handle(req, res)
let val
try {
val = await layer.handle(req, res)
} catch (err) {
if (!res.writableEnded) {
return sendError(res, err, true)
}
}
if (res.writableEnded) {
break
}
Expand Down

0 comments on commit 62fd25a

Please sign in to comment.