Better error handling
This commit is contained in:
9
index.ts
9
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(`<pre>${error}\n${error.stack}</pre>`, {
|
||||
headers: {
|
||||
"Content-Type": "text/html",
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Listening on http://localhost:${server.port}...`);
|
||||
|
||||
Reference in New Issue
Block a user