Skip to content

Commit

Permalink
bugfix: handle if errors is not an array
Browse files Browse the repository at this point in the history
closes mercurius-js#1024

check that error.originalError.errors is an array before mapping it.

if not an array, but is defined, try to handle it anyway.
  • Loading branch information
faizplus committed Feb 13, 2024
1 parent 70b2d88 commit ff30764
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ function defaultErrorFormatter (execution, ctx) {

// it handles fastify errors MER_ERR_GQL_VALIDATION
if (error.originalError?.errors) {
// not all errors are `GraphQLError` type, we need to convert them
return error.originalError.errors.map(toGraphQLError)
// error.originalError.errors is not always an array, we need to check it first
if (Array.isArray(error.originalError.errors)) {
// not all errors are `GraphQLError` type, we need to convert them
return error.originalError.errors.map(toGraphQLError);
}
return toGraphQLError(error.originalError.errors);
}

return error
Expand Down

0 comments on commit ff30764

Please sign in to comment.