-
Notifications
You must be signed in to change notification settings - Fork 23
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
adds 'url' to log context for rendering errors #687
Conversation
Pull Request Test Coverage Report for Build 2463
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏄♂️
When Amphora throws an error in a location where req/res context is available we don't currently include that context. This commit includes 'url' in the log context to make it easy to reproduce errors.
2e2d2a7
to
26abc48
Compare
lib/responses.js
Outdated
@@ -312,7 +312,7 @@ function unauthorized(res) { | |||
* @param {object} res | |||
*/ | |||
function clientError(err, res) { | |||
log('error', err.message, { stack: err.stack }); | |||
log('error', err.message, { stack: err.stack, url: res.locals.url }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Is a clientError
really worthy of generating an error
level log on the server side or should this be a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, but would also be a bit safer to use lodash _get(res, 'locals.url')
@reubenson yeah I was thinking about that too. The only situation I can think of where it wouldn't would be if someone added a middleware to wipe out that attribute or set it to a non-object (which seems like a mis-use of Express and maybe should result in a hard error?). Edit: We already import |
While `res.locals` is an object created by Express, it's not impossible to manually delete or override that attribute. Using `_.get(res, 'locals.url')` will provide some additional safety to the logging mechanism in the event of misuse.
When Amphora throws an error in a location where req/res context is
available we don't currently include that context.
This commit includes
url
in the log context to make it easy toreproduce errors.
According to the express docs
res.locals
is available by default and there is no risk of attempting to reference a property on anundefined
object under normal use.There may be more useful context available, but this seems like a good place to start.
For example,
res.locals.user
would log which user initiated an action (for internal requests usingamphora-auth
):https://github.com/clay/amphora-auth/blob/94201d60a6043c968b507a66e7ab289ce4f0139b/index.js#L144-L153