clean error handling

This commit is contained in:
marlonerler
2024-07-04 18:02:53 +02:00
parent 9649e3e522
commit 57d484a0e6
+5 -10
View File
@@ -6,7 +6,6 @@ import { ServerWebSocket } from "bun";
// CONFIG // CONFIG
const staticDir = "static/dist"; const staticDir = "static/dist";
const defaultPage = "index.html"; const defaultPage = "index.html";
const errorPage = "404.html";
// TYPES // TYPES
export type WS = ServerWebSocket<unknown>; export type WS = ServerWebSocket<unknown>;
@@ -19,15 +18,11 @@ const server = Bun.serve({
// respond // respond
const requestPath = new URL(request.url).pathname; const requestPath = new URL(request.url).pathname;
try { switch (requestPath) {
switch (requestPath) { case "/":
case "/": return createFileResponse(defaultPage);
return createFileResponse(defaultPage); default:
default: return createFileResponse(requestPath);
return createFileResponse(requestPath);
}
} catch {
return createFileResponse(errorPage);
} }
}, },