Skip to content

Commit

Permalink
fix reportErrors link example in docs (#11450)
Browse files Browse the repository at this point in the history
Co-authored-by: Jerel Miller <[email protected]>
  • Loading branch information
phryneas and jerelmiller authored Jan 2, 2024
1 parent b73dd1c commit 988f574
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions docs/source/api/link/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,23 @@ This style of link also composes well for customization using a function:
import { ApolloLink } from '@apollo/client';

const reportErrors = (errorCallback) => new ApolloLink((operation, forward) => {
const observable = forward(operation);
// errors will be sent to the errorCallback
observable.subscribe({ error: errorCallback })
return observable;
return new Observable((observer) => {
const observable = forward(operation);
const subscription = observable.subscribe({
next(value) {
observer.next(value);
},
error(networkError) {
errorCallback({ networkError, operation });
observer.error(networkError);
},
complete() {
observer.complete();
},
});

return () => subscription.unsubscribe();
});
});

const link = reportErrors(console.error);
Expand Down

0 comments on commit 988f574

Please sign in to comment.