Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/dedupe-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed Feb 8, 2025
2 parents a86bb0a + 6a99677 commit 3a41a63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/payload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ export const getPayload = async (
}
} catch (e) {
cached.promise = null
// add identifier to error object, so that our error logger in routeError.ts does not attempt to re-initialize getPayload
e.payloadInitError = true
throw e
}

Expand Down
13 changes: 13 additions & 0 deletions packages/payload/src/utilities/routeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export const routeError = async ({
err: APIError
req: PayloadRequest | Request
}) => {
if ('payloadInitError' in err && err.payloadInitError === true) {
// do not attempt initializing Payload if the error is due to a failed initialization. Otherwise,
// it will cause an infinite loop of initialization attempts and endless error responses, without
// actually logging the error, as the error logging code will never be reached.
console.error(err)
return Response.json(
{
message: 'There was an error initializing Payload',
},
{ status: httpStatus.INTERNAL_SERVER_ERROR },
)
}

let payload = incomingReq && 'payload' in incomingReq && incomingReq?.payload

if (!payload) {
Expand Down

0 comments on commit 3a41a63

Please sign in to comment.