From db9d0419edf6930cab2385fd7ece6e47c5131444 Mon Sep 17 00:00:00 2001 From: Julien Rousseau Date: Mon, 23 Oct 2023 16:22:20 -0400 Subject: [PATCH] fixed error --- index.ts | 10 +++++----- src/fetch/POST.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/index.ts b/index.ts index 2bacaa6..325083f 100644 --- a/index.ts +++ b/index.ts @@ -1,20 +1,20 @@ #!/usr/bin/env node import { config } from "./src/config.js"; -import { logger } from "./src/logger.js"; import GET from "./src/fetch/GET.js"; import POST from "./src/fetch/POST.js"; import PUT from "./src/fetch/PUT.js"; +import { logger } from "./src/logger.js"; if (config.verbose) logger.enable(); const app = Bun.serve({ hostname: config.hostname, port: config.port, - fetch(req: Request) { - if ( req.method == "GET" ) return GET(req); - if ( req.method == "POST") return POST(req); - if ( req.method == "PUT") return PUT(req); + fetch: function fetch(req: Request) { + if (req.method == "GET") return GET(req); + if (req.method == "POST") return POST(req); + if (req.method == "PUT") return PUT(req); return new Response("Invalid request", { status: 400 }); }, }); diff --git a/src/fetch/POST.ts b/src/fetch/POST.ts index fe734eb..83a7373 100644 --- a/src/fetch/POST.ts +++ b/src/fetch/POST.ts @@ -11,6 +11,7 @@ export default async function (req: Request) { // parse POST body payload try { + sink_requests?.inc(); const body = BodySchema.parse(JSON.parse(text)); if ("message" in body) { @@ -19,9 +20,8 @@ export default async function (req: Request) { } return handleSinkRequest(body); - } catch { + } catch (err) { sink_request_errors?.inc(); - } finally { - sink_requests?.inc(); + return new Response("invalid request: " + JSON.stringify(err), { status: 400 }); } }