Better error handling

This commit is contained in:
2024-02-04 13:45:15 +03:00
parent 6c3d5c0ffc
commit 8cd20b529f

View File

@@ -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(`<pre>${error}\n${error.stack}</pre>`, {
headers: {
"Content-Type": "text/html",
},
});
},
});
console.log(`Listening on http://localhost:${server.port}...`);