Skip to content

Commit 62fabe8

Browse files
committed
Add unification of the error property
1 parent d3f320b commit 62fabe8

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

docs/source/migrating/apollo-client-4-migration.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,25 @@ useQuery(QUERY, {
10071007
10081008
## New error handling
10091009
1010+
Error handling in Apollo Client 4 has changed significantly to be more predictable and intuitive.
1011+
1012+
### Unification of the `error` property
1013+
1014+
In Apollo Client 3, many result types returned both the `error` and `errors` properties. This includes the result emitted from `ObservableQuery` and some React hooks such as `useQuery`. This made it difficult to determine which property should be used to determine the source of the error. This was further complicated by the fact that the `errors` property was set only when `errorPolicy` was `all`!
1015+
1016+
Apollo Client 4 unifies all errors into a single `error` property. If you check for `errors`, remove this check and use `error` instead.
1017+
1018+
```ts
1019+
const { error, errors } = useQuery(QUERY);// [!code --]
1020+
const { error } = useQuery(QUERY);// [!code ++]
1021+
1022+
if (error) {
1023+
// ...
1024+
} else if (errors) {// [!code --:2]
1025+
// ...
1026+
}
1027+
```
1028+
10101029
Error handling between Apollo Client 3 and 4 has changed significantly.
10111030
In Apollo Client 3, every error was wrapped in an `ApolloError` instance, which made it hard to figure out where the error initially came from and could cause problems with observability services.
10121031
In Apollo Client 4,

0 commit comments

Comments
 (0)