From 96ecf7e095a0cc72b50e3d63d8278bcbc896f06b Mon Sep 17 00:00:00 2001 From: Luke Winship Date: Mon, 23 Aug 2021 16:41:31 +0100 Subject: [PATCH] fix: Axios error logs include response body --- src/logger.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/logger.js b/src/logger.js index 4bd7084..2f01d35 100644 --- a/src/logger.js +++ b/src/logger.js @@ -30,7 +30,7 @@ function axiosErrorConfigToLoggableObject(error) { }; if (_.isString(error.config.data)) { // this can be ridiculously long so truncate it - returnError.axiosConfig.data = truncateString(64, error.config.data); + returnError.axiosConfig.data = truncateString(256, error.config.data); } return returnError; } @@ -40,6 +40,12 @@ function axiosErrorConfigToLoggableObject(error) { */ function errorToLoggableObject(error) { const returnError = { ...error }; + /* Without this, axios errors contain very limited information, as they have a .toJSON() function, which outputs + just things like error.stack and misses things like error.response.data. CircularJSON, which is our formatter for + logs, seems to use this `toJSON` function if it's there */ + if (typeof returnError.toJSON === 'function') { + delete returnError.toJSON; + } if (error instanceof Error) { // JS errors lose these attributes when converted to objects (lord knows why) returnError.name = error.name;