Skip to content

Commit ddaf849

Browse files
Log unexpected errors
1 parent 5b14c24 commit ddaf849

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lambdas/api-handler/src/mappers/error-mapper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { APIGatewayProxyResult } from "aws-lambda";
22
import { NotFoundError, ValidationError } from "../errors";
33
import { buildApiError, ApiErrorCode, ApiErrorDetail, ApiErrorTitle, ApiError, ApiErrorStatus } from "../contracts/errors";
4+
import pino from "pino";
45

6+
const logger = pino();
57
export interface ErrorResponse {
68
errors: ApiError[];
79
}
@@ -12,9 +14,12 @@ export function mapErrorToResponse(error: unknown): APIGatewayProxyResult {
1214
} else if (error instanceof NotFoundError) {
1315
return buildResponseFromErrorCode(ApiErrorCode.NotFound, error.detail);
1416
} else if (error instanceof Error) {
17+
logger.error({ err: error }, "Internal server error");
1518
return buildResponseFromErrorCode(ApiErrorCode.InternalServerError, error.message);
16-
} else
17-
return buildResponseFromErrorCode(ApiErrorCode.InternalServerError, "Unexpected error");
19+
} else {
20+
logger.error({ err: error }, "Internal server error (non-Error thrown)");
21+
return buildResponseFromErrorCode(ApiErrorCode.InternalServerError, "Unexpected error");
22+
}
1823
}
1924

2025
function buildResponseFromErrorCode(code: ApiErrorCode, detail: ApiErrorDetail | string): APIGatewayProxyResult {

0 commit comments

Comments
 (0)