From 8330a039cfc3c883d5342e71f75b1a6e38951cc4 Mon Sep 17 00:00:00 2001 From: Kevin Bulteel Date: Wed, 13 Mar 2024 20:51:11 +0100 Subject: [PATCH] fix again :) --- packages/@hec.js/api/lib/src/api.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/@hec.js/api/lib/src/api.js b/packages/@hec.js/api/lib/src/api.js index a13e4a0..7098f55 100644 --- a/packages/@hec.js/api/lib/src/api.js +++ b/packages/@hec.js/api/lib/src/api.js @@ -73,7 +73,7 @@ export class API { const stack = [], paramPointer = new WeakMap(); - /** @type { () => Promise | null } */ + /** @type { () => Response | Promise | null } */ const next = () => { const r = stack.shift(); @@ -129,16 +129,13 @@ export class API { findRoutes(apiRequest, this.#routes); - const r = await next()?.catch((error) => { + try { + return await next() ?? new Response(context.response, { status: context.status }); + } catch (error) { console.error(error); - context.response = '{"error": 0, "message": "See logs for information"}'; - context.status = 500; - - return null; - }); - - return r ?? new Response(context.response, { status: context.status }); + return Response.json({ error: 0, message: 'See logs for details' }, { status: 500 }); + } } serve() {