Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-link-error

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link-error

Error Apollo Link for GraphQL Network Stack

  • 1.1.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
398K
decreased by-2.98%
Maintainers
3
Weekly downloads
 
Created

What is apollo-link-error?

The apollo-link-error package is used in Apollo Client to handle GraphQL errors. It allows developers to intercept and respond to errors that occur during GraphQL operations, such as network errors or GraphQL errors returned by the server.

What are apollo-link-error's main functionalities?

Error Handling

This feature allows you to handle both GraphQL and network errors. The onError function takes a callback that receives an object containing graphQLErrors and networkError. You can then log or handle these errors as needed.

const { onError } = require('apollo-link-error');

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

Retry Logic

This feature allows you to implement retry logic for network errors. If a network error occurs, the operation is retried after a specified delay (e.g., 3000 milliseconds).

const { onError } = require('apollo-link-error');
const { ApolloLink, Observable } = require('apollo-link');

const retryLink = onError(({ networkError, operation, forward }) => {
  if (networkError) {
    return new Observable(observer => {
      setTimeout(() => {
        forward(operation).subscribe({
          next: observer.next.bind(observer),
          error: observer.error.bind(observer),
          complete: observer.complete.bind(observer),
        });
      }, 3000);
    });
  }
});

Custom Error Handling

This feature allows you to customize error handling based on specific error messages or types. For example, you can handle 'UNAUTHENTICATED' errors differently by logging a specific message or taking other actions.

const { onError } = require('apollo-link-error');

const customErrorLink = onError(({ response, operation }) => {
  if (response.errors) {
    response.errors = response.errors.map(error => {
      if (error.message === 'UNAUTHENTICATED') {
        // Custom handling for unauthenticated errors
        console.log('User is unauthenticated');
      }
      return error;
    });
  }
});

Other packages similar to apollo-link-error

FAQs

Package last updated on 09 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc