fase(23): observability and health probes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
debian
2026-03-08 06:10:24 -04:00
parent ddb4f66036
commit 629eafecd8
5 changed files with 34 additions and 15 deletions

View File

@@ -51,10 +51,12 @@ class RateLimitError extends AppError {
}
exports.RateLimitError = RateLimitError;
function globalErrorHandler(err, req, res, _next) {
const logger = req.log;
const authReq = req;
const logger = authReq.log;
const userId = authReq.user?.id;
if (err instanceof AppError && err.isOperational) {
if (logger) {
logger.warn({ err, statusCode: err.statusCode }, err.message);
logger.warn({ err, statusCode: err.statusCode, userId }, err.message);
}
const body = { error: err.message, code: err.code };
if (err instanceof ValidationError && err.details !== undefined) {
@@ -64,7 +66,7 @@ function globalErrorHandler(err, req, res, _next) {
return;
}
if (logger) {
logger.error({ err }, 'Unhandled error');
logger.error({ err, userId }, 'Unhandled error');
}
else {
console.error('Unhandled error', err);