Skip to content

Commit

Permalink
catch exceptions in handler function and wait until handler completes (
Browse files Browse the repository at this point in the history
…#251)

* catch exceptions in handler function and also wait until the handler function is complete

Signed-off-by: karthik2804 <[email protected]>

* fix review comments

Signed-off-by: karthik2804 <[email protected]>

---------

Signed-off-by: karthik2804 <[email protected]>
  • Loading branch information
karthik2804 authored Jul 19, 2024
1 parent 61703eb commit e1a417a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion templates/http-ts/content/src/spin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@ async function handleEvent(event: FetchEvent) {

let res = new ResponseBuilder(resolve);

await handler(event.request, res)
try {
// In case you want to do some 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) {
if (res.getStatus() == 200) {
res.status(500);
}
res.send(`error in handler: ${e}`);
}
}

0 comments on commit e1a417a

Please sign in to comment.