Package Exports
- apollo-link-error
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (apollo-link-error) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
title: apollo-link-error description: Handle and inspect errors in your GraphQL network stack.
Use this link to do some custom logic when a GraphQL or network error happens:
import { onError } from "apollo-link-error";
const link = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
if (networkError) console.log(`[Network error]: ${networkError}`);
});
Apollo Link is a system of modular components for GraphQL networking. Read the docs to learn how to use this link with libraries like Apollo Client and graphql-tools, or as a standalone client.
Callback
Error Link takes a function that is called in the event of an error. This function is called with an object containing the following keys:
operation
: The Operation that erroredresponse
: The result returned from lower down in the link chaingraphQLErrors
: An array of errors from the GraphQL endpointnetworkError
: Any error during the link execution or server response, that wasn't delivered as part of theerrors
field in the GraphQL result
Error categorization
An error is passed as a networkError
if a link further down the chain called the error
callback on the observable. In most cases, graphQLErrors
is the errors
field of the result from the last next
call.
A networkError
can contain additional fields, such as a GraphQL object in the case of a failing HTTP status code from apollo-link-http
. In this situation, graphQLErrors
is an alias for networkError.result.errors
if the property exists.
Ignoring errors
If you want to conditionally ignore errors, you can set response.errors = null;
within the error handler:
onError(({ response, operation }) => {
if (operation.operationName === "IgnoreErrorsQuery") {
response.errors = null;
}
});