From 41906abaf9e210991616c03929af443bfbede5bc Mon Sep 17 00:00:00 2001 From: perf3ct Date: Mon, 9 Jun 2025 00:08:06 +0000 Subject: [PATCH] feat(route): allow for routes to handle their own response --- apps/server/src/routes/route_api.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/server/src/routes/route_api.ts b/apps/server/src/routes/route_api.ts index 5a4f490c8..1b4ea48f2 100644 --- a/apps/server/src/routes/route_api.ts +++ b/apps/server/src/routes/route_api.ts @@ -158,6 +158,11 @@ function handleException(e: unknown | Error, method: HttpMethod, path: string, r log.error(`${method} ${path} threw exception: '${errMessage}', stack: ${errStack}`); + // Skip sending response if it's already been handled by the route handler + if ((res as unknown as { triliumResponseHandled?: boolean }).triliumResponseHandled || res.headersSent) { + return; + } + const resStatusCode = (e instanceof ValidationError || e instanceof NotFoundError) ? e.statusCode : 500; res.status(resStatusCode).json({