Skip to content

Commit

Permalink
fix: prevent error-handler to keep stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-gs committed Feb 7, 2024
1 parent 3a3adfb commit a16e078
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/app/middleware/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@ export default function errorHandler(
const { path, user } = req;
const handlerPath = '/' + path.split('/').slice(2).join('/');

if (err.status === 401) {
return;
}

if (user) {
req.logger?.error(
'%s ERROR for user %s: %s Stack: %s. Payload %s',
handlerPath,
user.email,
err.message,
err.stack,
req.body ? JSON.stringify(req.body) : 'NO PAYLOAD'
);
} else {
req.logger?.error('%s ERROR %s Stack: %s', handlerPath, err.message, err.stack);
if (err.status !== 401) {
if (user) {
req.logger?.error(
'%s ERROR for user %s: %s Stack: %s. Payload %s',
handlerPath,
user.email,
err.message,
err.stack,
req.body ? JSON.stringify(req.body) : 'NO PAYLOAD'
);
} else {
req.logger?.error('%s ERROR %s Stack: %s', handlerPath, err.message, err.stack);
}
}

if (res.headersSent) {
Expand Down

0 comments on commit a16e078

Please sign in to comment.