Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with errorLogger msg always returning 200 for res.statusCode #279

Open
dkarkar92 opened this issue Oct 13, 2022 · 0 comments
Open

Comments

@dkarkar92
Copy link

Versions:

  • express-winston: "4.2.0"
  • winston: "3.8.2"

I have a expressWinston.logger and expressWinston.errorLogger setup currently. If my application throws an error, say 403 for instance, the expressWinston.logger will log that correctly. Example:

{
  meta: {},
  level: 'info',
  message: 'PATCH /xyz/123 403 405ms',
  timestamp: '2022-10-13T17:06:57.871Z',
}

The issue is that the errorLogger does not correctly report the statusCode properly. It will always return 200 rendering the message {{res.statusCode}} field useless for me. See:

{
  meta: {
    error: .../serverError.ts:25
      return new Exception(errObj.status, errObj.message, errObj.errorCode)
             ^

    Error: User does not have permissions to create or modify users
      ...
      status: 403,
      errorCode: '70060'
    },
    level: 'error',
    message: 'uncaughtException: User does not have permissions to create or modify users\n ...'
    exception: true,
    date: 'Thu Oct 13 2022 17:06:57 GMT+0000 (Coordinated Universal Time)',
    process: {...},
    os: { ... },
    trace: [...],
    req: {
      url: '...,
      headers: {...},
      method: 'PATCH',
      httpVersion: '1.1',
      originalUrl: '...',
      query: {}
    }
  },
  level: '\x1B[31merror\x1B[39m',
  message: 'User does not have permissions to create or modify users - 200 PATCH ...'
}

and the config for the errorLogger (note this isn't my live prod code, just something I modified to reproduce the error in my app):

  app.use(errorLogger({
    transports: [
      new transports.Console()
    ],
    level: 'error',
    msg: `{{err.message}} - {{res.statusCode}} {{req.method}} {{req.url}}`,
    format: format.combine(
      format.colorize(),
      format.json(),
      format.prettyPrint(),
    )
  }));

Question: Is this a known issue? Or is there something wrong my my config? Or is there an issue with how my error is being thrown? What am I missing? I want my errorLogger to accurately report the 403 error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant