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: Error Link
Purpose
An Apollo Link to allow sending error events to custom services or loggers.
Installation
npm install apollo-link-error --save
Usage
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}`);
})
Options
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 Execution of the reponsegraphQLErrors
: An array of errors from the GraphQL endpointnetworkError
: any error during the link execution or server response
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;
}
})
Context
The Error Link does not use the context for anything