Skip to content

Commit

Permalink
fix: allow public errors to thread through on response (#10419)
Browse files Browse the repository at this point in the history
### What?
When using `throw new APIResponse("Custom error message", 500, null,
true)` the error message is being replaced with the standard "Something
went wrong" message.

### Why?
We are not checking if the 4th argument (`isPublic`) is false before
masquerading the error message.

### How?
Adds a check for `!err.isPublic` before adjusting the outgoing message.
  • Loading branch information
JarrodMFlesch authored Feb 4, 2025
1 parent b671fd5 commit ea9abfd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/payload/src/utilities/routeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const routeError = async ({

// 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) {
if (!config.debug && !err.isPublic && status === httpStatus.INTERNAL_SERVER_ERROR) {
response = formatErrors(new APIError('Something went wrong.'))
}

Expand Down

0 comments on commit ea9abfd

Please sign in to comment.