Skip to content

Commit

Permalink
fix again :)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBLT committed Mar 13, 2024
1 parent ab8aa3a commit 8330a03
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/@hec.js/api/lib/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class API {
const stack = [],
paramPointer = new WeakMap();

/** @type { () => Promise<Response> | null } */
/** @type { () => Response | Promise<Response> | null } */
const next = () => {
const r = stack.shift();

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 8330a03

Please sign in to comment.