1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

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.
This commit is contained in:
Thomas Heartman 2023-06-07 14:11:34 +02:00 committed by GitHub
parent 81e461a53f
commit 03dd7b6863
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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:`,
`I encountered an error that wasn't an instance of the \`UnleashError\` type. The original error was: ${format(
error,
finalError,
)}. 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();