diff --git a/templates/http-ts/content/src/spin.ts b/templates/http-ts/content/src/spin.ts index b745952f..697c77f8 100644 --- a/templates/http-ts/content/src/spin.ts +++ b/templates/http-ts/content/src/spin.ts @@ -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}`); + } } \ No newline at end of file