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({