Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand error types to match actual error data #6319

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
- `useQuery`: Prevent new data re-render attempts during an existing render. This helps avoid React 16.13.0's "Cannot update a component from inside the function body of a different component" warning (https://github.com/facebook/react/pull/17099). <br/>
[@hwillson](https://github.com/hwillson) in [#6107](https://github.com/apollographql/apollo-client/pull/6107)

- Expand `ApolloError` typings to include `ServerError` and `ServerParseError`. <br/>
[@dmarkow](https://github.com/dmarkow) in [#6319](https://github.com/apollographql/apollo-client/pull/6319)

## Apollo Client 2.6.8

### Apollo Client (2.6.8)
Expand Down
6 changes: 4 additions & 2 deletions src/errors/ApolloError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { GraphQLError } from 'graphql';

import { isNonEmptyArray } from '../utilities/common/arrays';
import { ServerParseError } from '../link/http/parseAndCheckHttpResponse';
import { ServerError } from '../link/utils/throwServerError';

export function isApolloError(err: Error): err is ApolloError {
return err.hasOwnProperty('graphQLErrors');
Expand Down Expand Up @@ -34,7 +36,7 @@ const generateErrorMessage = (err: ApolloError) => {
export class ApolloError extends Error {
public message: string;
public graphQLErrors: ReadonlyArray<GraphQLError>;
public networkError: Error | null;
public networkError: Error | ServerParseError | ServerError | null;

// An object that can be used to provide some additional information
// about an error, e.g. specifying the type of error this is. Used
Expand All @@ -51,7 +53,7 @@ export class ApolloError extends Error {
extraInfo,
}: {
graphQLErrors?: ReadonlyArray<GraphQLError>;
networkError?: Error | null;
networkError?: Error | ServerParseError | ServerError | null;
errorMessage?: string;
extraInfo?: any;
}) {
Expand Down