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 27, 2024
1 parent 536aa10 commit 646c227
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 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,16 @@ async function handleEvent(event: FetchEvent) {

let res = new ResponseBuilder(resolve);

await handler(event.request, res)
try {
// In case you want to do sonme work after the response is sent
// uncomment the line below and comment out the line with
// `await handler(event.request, res)
// event.waitUntil(handler(event.request, res))
await 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 646c227

Please sign in to comment.