Skip to content

Commit

Permalink
Update errorFormatter in options.md (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
linkthai authored Oct 16, 2023
1 parent c4ad740 commit f3bbce2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/api/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,25 @@ app.register(mercurius, {
errorFormatter: (result) => ({ statusCode: result.errors[0].originalError.statusCode, response: result })
})
```

Using the errorFormatter means overriding the `defaultErrorFormatter` and it could cause ambiguous GraphQL error message like `GraphQL validation error` without indicating where and why the error happens. To retain the default error behaviour, you can reimplement the `defaultErrorFormatter`.
```javascript
import mercurius from 'mercurius';
const { defaultErrorFormatter } = mercurius;

app.register(mercurius, {
schema,
resolvers,
errorFormatter: (result, context) => {
const formatter = defaultErrorFormatter(result, context);

// your custom behaviour here

return {
statusCode: formatter.statusCode || 500,
response: formatter.response,
};
},
});

```

0 comments on commit f3bbce2

Please sign in to comment.