Skip to content

Commit

Permalink
catch exceptions in handler function and also wait until the handler …
Browse files Browse the repository at this point in the history
…function is complete

Signed-off-by: karthik2804 <[email protected]>
  • Loading branch information
karthik2804 committed Jun 25, 2024
1 parent 536aa10 commit b179657
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion templates/http-ts/content/src/spin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ async function handleEvent(event: FetchEvent) {

let res = new ResponseBuilder(resolve);

await handler(event.request, res)
try {
event.waitUntil(handler(event.request, res))
} catch (e: any) {
res.status(500)
res.send(`error in handler: ${e}`)
}
}

// Keep wizer happy during pre-init. Should go away
Expand Down

0 comments on commit b179657

Please sign in to comment.