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

This commit is contained in:
perf3ct 2025-06-09 00:08:06 +00:00
parent ca6277f6e9
commit 41906abaf9
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232

View File

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