From 1ca2b9948bb38b875601c3d7b6fdf481e963d2cb Mon Sep 17 00:00:00 2001 From: James Gregory Date: Wed, 12 Jan 2022 08:38:22 +1100 Subject: [PATCH] fix(log): errors not being logged correctly --- src/bin/start.ts | 2 +- src/server/server.ts | 4 ++-- src/services/lambda.ts | 6 +++--- src/services/triggers/customMessage.ts | 2 +- src/services/triggers/postAuthentication.ts | 2 +- src/services/triggers/postConfirmation.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bin/start.ts b/src/bin/start.ts index 47743184..fabec0b0 100644 --- a/src/bin/start.ts +++ b/src/bin/start.ts @@ -36,6 +36,6 @@ createDefaultServer(logger) logger.info(`Cognito Local running on http://${url}`); }) .catch((err) => { - logger.error({ error: err }); + logger.error(err); process.exit(1); }); diff --git a/src/server/server.ts b/src/server/server.ts index 833e8149..03ca8789 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -108,14 +108,14 @@ export const createServer = ( unsupported(ex.message, res, req.log); return; } else if (ex instanceof CognitoError) { - req.log.warn({ error: ex }, `Error handling target: ${target}`); + req.log.warn(ex, `Error handling target: ${target}`); res.status(400).json({ code: ex.code, message: ex.message, }); return; } else { - req.log.error({ error: ex }, `Error handling target: ${target}`); + req.log.error(ex, `Error handling target: ${target}`); res.status(500).json(ex); return; } diff --git a/src/services/lambda.ts b/src/services/lambda.ts index 9fbade63..b4001b3b 100644 --- a/src/services/lambda.ts +++ b/src/services/lambda.ts @@ -226,7 +226,7 @@ export class LambdaService implements Lambda { }) .promise(); } catch (ex) { - ctx.logger.error({ error: ex }); + ctx.logger.error(ex); throw new UnexpectedLambdaExceptionError(); } @@ -239,11 +239,11 @@ export class LambdaService implements Lambda { return parsedPayload.response; } catch (err) { - ctx.logger.error({ error: err }); + ctx.logger.error(err); throw new InvalidLambdaResponseError(); } } else { - ctx.logger.error({ error: result.FunctionError }); + ctx.logger.error(result.FunctionError); throw new UserLambdaValidationError(result.FunctionError); } } diff --git a/src/services/triggers/customMessage.ts b/src/services/triggers/customMessage.ts index c6ba0d62..c6da4550 100644 --- a/src/services/triggers/customMessage.ts +++ b/src/services/triggers/customMessage.ts @@ -83,7 +83,7 @@ export const CustomMessage = .replace(AWS_USERNAME_PARAMETER, username), }; } catch (ex) { - ctx.logger.error({ error: ex }); + ctx.logger.error(ex); return null; } }; diff --git a/src/services/triggers/postAuthentication.ts b/src/services/triggers/postAuthentication.ts index 487f19a0..e461be53 100644 --- a/src/services/triggers/postAuthentication.ts +++ b/src/services/triggers/postAuthentication.ts @@ -42,6 +42,6 @@ export const PostAuthentication = userPoolId, }); } catch (err) { - ctx.logger.warn({ error: err }, "PostAuthentication error, ignored"); + ctx.logger.warn(err, "PostAuthentication error, ignored"); } }; diff --git a/src/services/triggers/postConfirmation.ts b/src/services/triggers/postConfirmation.ts index 8ff862bf..4dbe5d6e 100644 --- a/src/services/triggers/postConfirmation.ts +++ b/src/services/triggers/postConfirmation.ts @@ -45,6 +45,6 @@ export const PostConfirmation = userPoolId, }); } catch (ex) { - ctx.logger.error({ error: ex }); + ctx.logger.error(ex); } };