From fc8096f3e12ae18c9adf886194e8c95bf0cbb096 Mon Sep 17 00:00:00 2001 From: Axel Vermeil Date: Tue, 7 Jul 2020 12:59:45 +0000 Subject: [PATCH] hack: make the error middleware always tell us what caused the 500 --- src/middleware/error-responder.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/middleware/error-responder.js b/src/middleware/error-responder.js index aa9af2d0..477fd442 100644 --- a/src/middleware/error-responder.js +++ b/src/middleware/error-responder.js @@ -1,13 +1,16 @@ -const http = require('http'); -const _ = require('lodash'); +const http = require("http"); +const _ = require("lodash"); // This reponder is assuming that all <500 errors are safe to be responded // with their .message attribute. // DO NOT write sensitive data into error messages. function createErrorResponder(_opts) { - const opts = _.merge({ - isErrorSafeToRespond: status => status < 500, - }, _opts); + const opts = _.merge( + { + isErrorSafeToRespond: (status) => status < 500, + }, + _opts + ); // 4 params needed for Express to know it's a error handler middleware // eslint-disable-next-line @@ -16,14 +19,15 @@ function createErrorResponder(_opts) { const status = err.status ? err.status : 500; const httpMessage = http.STATUS_CODES[status]; - if (opts.isErrorSafeToRespond(status)) { + // Always tell us what's wrong + if (true || opts.isErrorSafeToRespond(status)) { // eslint-disable-next-line message = err.message; } else { message = httpMessage; } - const isPrettyValidationErr = _.has(err, 'errors'); + const isPrettyValidationErr = _.has(err, "errors"); const body = isPrettyValidationErr ? JSON.stringify(err) : { status, statusText: httpMessage, messages: [message] };