Skip to content

Commit a3a65bb

Browse files
kabachookabernix
authored andcommitted
docs(error-handling): add originalError property description (#2968)
* docs(error-handling): add originalError property description * Update errors.md
1 parent 6074990 commit a3a65bb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/source/features/errors.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ server.listen().then(({ url }) => {
150150
});
151151
```
152152

153+
The error instance received by `formatError` (a `GraphQLError`) contains an `originalError` property which represents the original error thrown within the resolver. This can be used to `instanceof` check against a specific error class, such as `AuthenticationError`, `ValidationError`, etc.:
154+
155+
```js
156+
/* ... */
157+
formatError(err) {
158+
if (err.originalError instanceof AuthenticationError) {
159+
return new Error('Different authentication error message!');
160+
}
161+
},
162+
/* ... */
163+
```
164+
165+
> To make context-specific adjustments to the error received by `formatError` (e.g. localization or personalization), consider using the `didEncounterErrors` life-cycle hook to attach additional properties to the error, which can be accessed andn utilized within `formatError`.
166+
153167
### For Apollo Engine reporting
154168

155169
With the Apollo Platform, it's possible to observe error rates within Apollo

0 commit comments

Comments
 (0)