Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

OnError Apollo i will like to show/display the error #1281

Open
unutoiul opened this issue May 30, 2020 · 3 comments
Open

OnError Apollo i will like to show/display the error #1281

unutoiul opened this issue May 30, 2020 · 3 comments

Comments

@unutoiul
Copy link

unutoiul commented May 30, 2020

const errorLink: any = onError(
    ({ operation, forward, graphQLErrors, networkError }) => {
       const { dispatchModal } = useContext<IModalContext>(ModalContext);
        console.log(operation);
        console.log(forward);

        if (graphQLErrors) {
            graphQLErrors.forEach(({ message, locations, path }) =>
                console.log(
                    `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
                )
            );
        }

        if (networkError) {
            console.log(`[Network error]: ${networkError}`);
        }
    }
);

in the code above I will like to get set the useContext of another react component but I get

Error: Invalid hook call. Hooks can only be called inside of the body of a function component

which is normal, but how can I actually display an error in a component or change the state of another component from onError function with apollo?

@unutoiul unutoiul changed the title OnERROR Apollo i will like to show/display the error OnError Apollo i will like to show/display the error May 30, 2020
@cmnstmntmn
Copy link

cmnstmntmn commented Jun 13, 2020

@unutoiul did you found an workaround for this issue?

@unutoiul
Copy link
Author

I have not, Did u find any?

@cmnstmntmn
Copy link

a silly hack

    return new Observable((observer) => {
      return observer.error([...graphQLErrors, networkError]);
    });

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants