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

Fix request on error logger #45

Merged
merged 4 commits into from
Jan 28, 2018
Merged

Fix request on error logger #45

merged 4 commits into from
Jan 28, 2018

Conversation

natanavra
Copy link
Contributor

@natanavra natanavra commented Jan 25, 2018

The err param in onResFinished(err) was always undefined no matter what the result of the request was.

From nodejs / express documentation, there is no event named error:

The res object can be used as a the err holder, and set on the res object in the express error handler middleware

function onErrorMiddleware(err, req, res, next) {
    res.err = err;
    //code
}

If no err object on the response but a bad statusCode, we generate the error from the logger. I know this would show a somewhat confusing stack, but it's something.
Besides the stdSerializers.err handles string error as an array of chars.

'err' is never passed into the event callback, use the response object as the err transport
@natanavra natanavra changed the title Fix on error logger Fix request on error logger Jan 25, 2018
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Can you add a unit test for this?

@mcollina
Copy link
Member

Thinking about it some more, I think we have to support both things, as other frameworks might emit errors as 'error' events, can you please maintain the previous functionality while adding this one?

@natanavra
Copy link
Contributor Author

I was pretty sure this is an express only package, since I came here from express-pino-logger

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

logger.js Outdated

var log = this.log
var responseTime = Date.now() - this[startTime]

if (err) {
if (err || this.err || this.statusCode >= 400) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be >= 500, not 400.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you'd want to have logs of issues like: bad request, unauthorized, forbidden access

And besides, we want to log the request / response, and a 4xx is a request (client) error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non of them are errors.
This is a flow for error conditions.

@jsumners what do you think?

Copy link
Contributor Author

@natanavra natanavra Jan 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more point on my side, if I'd look at a logs dashboard, I'd be looking to see 4xx responses as errors. These can indicate a broken client side library, broken flow somewhere, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it got resolved before I came around. I'm fine with the current solution.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m very opposed to land this in the current form.

I’m also ok in removing the check on the status code (as it was before).

@natanavra
Copy link
Contributor Author

Basically, we can leave it up to the user to set the err on the res, that would probably still result in 4xx errors being logged, as I guess most developers would call next(err4xx);.

@mcollina
Copy link
Member

I think so, yes.

@natanavra
Copy link
Contributor Author

Modified. Not sure it notified you, as the commit and your message happened pretty much the same time... so I'm sending a message.

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit 7169c02 into pinojs:master Jan 28, 2018
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

Successfully merging this pull request may close these issues.

4 participants