Giter Site home page Giter Site logo

Comments (5)

 avatar commented on August 26, 2024 43

@valerybugakov take a look at apollo-error-link

Compose this with your httpLink like this:

import { ApolloClient } from 'apollo-client';
import { ApolloLink } from 'apollo-link';
import { createHttpLink } from 'apollo-link-http';
import { onError } from 'apollo-link-error';
import { InMemoryCache } from 'apollo-cache-inmemory';

const errorLink = onError(({ networkError, graphQLErrors }) => {
  if (graphQLErrors) {
    graphQLErrors.map(({ message, locations, path }) =>
      console.log(
        `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
      ),
    );
  }
  if (networkError) console.log(`[Network error]: ${networkError}`);
});

const httpLink = createHttpLink({ ... });

const link = ApolloLink.from([
  ...otherLinksIfNeeded,
  errorLink,
  httpLink,
]);

const client = new ApolloClient({
  link,
  cache: new InMemoryCache(),
  queryDeduplication: true,
});

from apollo-link.

coyolero avatar coyolero commented on August 26, 2024 42

@jbaxleyiii
What about if I want to catch a network Error?
Lets say a 400, bad request.

from apollo-link.

valerybugakov avatar valerybugakov commented on August 26, 2024

@somehandle yep, it's an option. What if I want to handle errors in my custom link? I found the only way to do it is to wrap Observable returned by next(operation) into another Observable.

from apollo-link.

jbaxleyiii avatar jbaxleyiii commented on August 26, 2024

@valerybugakov what kind of errors do you want to handle? If they are Graphql Errors, you can use .map on the result of forward(operation) since they are returned as a result, if not, you need to subscribe around the other observer. Take a look at the code behind apollo-link-error for some examples!

from apollo-link.

vjpr avatar vjpr commented on August 26, 2024

@coyolero Related #570

from apollo-link.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.