From 03dd7b68638d7e423fa9ec640b1042c13d29e76b Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Wed, 7 Jun 2023 14:11:34 +0200 Subject: [PATCH] chore: clarify error logs (#3915) This change makes the logs that happen when we encounter an error a little bit clearer. It logs the error message before the error ID and also logs the full serialized message just in case. --- src/lib/routes/util.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lib/routes/util.ts b/src/lib/routes/util.ts index e02f8591f5..af8b81b5f3 100644 --- a/src/lib/routes/util.ts +++ b/src/lib/routes/util.ts @@ -30,18 +30,29 @@ export const handleErrors: ( const finalError = error instanceof UnleashError ? error : fromLegacyError(error); + const format = (thing: object) => JSON.stringify(thing, null, 2); + if (!(error instanceof UnleashError)) { logger.debug( - `I encountered an error that wasn't an instance of the \`UnleashError\` type. The original error and what it was mapped to are:`, - error, - finalError, + `I encountered an error that wasn't an instance of the \`UnleashError\` type. The original error was: ${format( + error, + )}. It was mapped to ${format(finalError.toJSON())}`, ); } - logger.warn(finalError.id, finalError.message); + logger.warn( + `Original error message: ${error.message}. Processed error message: "${ + finalError.message + }" Error ID: "${finalError.id}". Full, serialized error: ${format( + finalError.toJSON(), + )}`, + ); if (['InternalError', 'UnknownError'].includes(finalError.name)) { - logger.error('Server failed executing request', error); + logger.error( + `Server failed executing request: ${format(error)}`, + error, + ); } return res.status(finalError.statusCode).json(finalError).end();