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();