Skip to content

Build your personal knowledge base with Trilium Notes

feat(route): allow for routes to handle their own response

perf3ct41906abaf9e2
diff --git a/apps/server/src/routes/route_api.ts b/apps/server/src/routes/route_api.ts
index 5a4f490c89..1b4ea48f24 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({