From 988f574df384d2cd36f625f267a643d5032e93af Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 2 Jan 2024 18:44:00 +0100 Subject: [PATCH] fix `reportErrors` link example in docs (#11450) Co-authored-by: Jerel Miller --- docs/source/api/link/introduction.mdx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/source/api/link/introduction.mdx b/docs/source/api/link/introduction.mdx index 200d8dc7aed..80d390c40ca 100644 --- a/docs/source/api/link/introduction.mdx +++ b/docs/source/api/link/introduction.mdx @@ -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);