From ace755742ce56b202f31cb239f69c4b72b1344e6 Mon Sep 17 00:00:00 2001 From: James Mikrut Date: Fri, 24 Jan 2025 14:06:01 -0500 Subject: [PATCH] chore: improves routeError log safety (#10793) Improves the logging that `routeError` throws. Logs were sometimes being swallowed if there was a problem with the incoming request. Now they will surface. --- packages/payload/src/utilities/routeError.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/payload/src/utilities/routeError.ts b/packages/payload/src/utilities/routeError.ts index dd95222d74..13d9e3c24c 100644 --- a/packages/payload/src/utilities/routeError.ts +++ b/packages/payload/src/utilities/routeError.ts @@ -37,6 +37,12 @@ export const routeError = async ({ } } + let response = formatErrors(err) + + let status = err.status || httpStatus.INTERNAL_SERVER_ERROR + + logError({ err, payload }) + const req = incomingReq as PayloadRequest req.payload = payload @@ -47,12 +53,6 @@ export const routeError = async ({ const { config } = payload - let response = formatErrors(err) - - let status = err.status || httpStatus.INTERNAL_SERVER_ERROR - - logError({ err, payload }) - // Internal server errors can contain anything, including potentially sensitive data. // Therefore, error details will be hidden from the response unless `config.debug` is `true` if (!config.debug && status === httpStatus.INTERNAL_SERVER_ERROR) {