From 2e2d2a7cc27465af59d560e440f8244dcd6ccd52 Mon Sep 17 00:00:00 2001 From: Matt Oberle Date: Thu, 17 Sep 2020 15:38:41 -0400 Subject: [PATCH] adds 'url' to log context for rendering errors 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. --- lib/render.js | 4 ++-- lib/responses.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/render.js b/lib/render.js index 372301f8..df140462 100644 --- a/lib/render.js +++ b/lib/render.js @@ -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 @@ -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: req.url })); } /** diff --git a/lib/responses.js b/lib/responses.js index 51321100..eec7a2c1 100644 --- a/lib/responses.js +++ b/lib/responses.js @@ -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; @@ -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;