From 8cd20b529fc13283e30eda84d412fafed0414092 Mon Sep 17 00:00:00 2001 From: anatolykopyl Date: Sun, 4 Feb 2024 13:45:15 +0300 Subject: [PATCH] Better error handling --- index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index fab135a..fcbc8d4 100644 --- a/index.ts +++ b/index.ts @@ -6,7 +6,7 @@ const server = Bun.serve({ port: PORT, async fetch(req) { if (!req.body) { - throw new Error("woops!"); + throw new Error("No body provided"); } const submittedData = await req.json(); @@ -25,6 +25,13 @@ ${JSON.stringify(submittedData, null, 2)} } }); }, + error(error) { + return new Response(`
${error}\n${error.stack}
`, { + headers: { + "Content-Type": "text/html", + }, + }); + }, }); console.log(`Listening on http://localhost:${server.port}...`);