Skip to content

Commit

Permalink
adds 'url' to log context for rendering errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattoberle committed Sep 18, 2020
1 parent db43aed commit 26abc48
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function renderComponent(req, res, hrStart) {
options = options || {};

if (renderer instanceof Error) {
log('error', renderer);
log('error', renderer, { url: res.locals.url });
return Promise.reject(renderer);
}
// Add request route params, request query params
Expand All @@ -88,7 +88,7 @@ function renderComponent(req, res, hrStart) {
.then(cmptData => formDataForRenderer(cmptData, { _ref }, locals))
.tap(logTime(hrStart, _ref))
.then(({data, options}) => renderer.render(data, options, res))
.catch(err => log('error', err));
.catch(err => log('error', err, { url: res.locals.url }));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function notFound(err, res) {
*/
function serverError(err, res) {
// error is required to be logged
log('error', err.message, { stack: err.stack });
log('error', err.message, { stack: err.stack, url: res.locals.url });

const message = err.message || 'Server Error', // completely hide these messages from outside
code = 500;
Expand Down Expand Up @@ -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 });
// They know it's a 400 already, we don't need to repeat the fact that its an error.
const message = removePrefix(err.message, ':'),
code = 400;
Expand Down

0 comments on commit 26abc48

Please sign in to comment.