React-apollo: Custom error details not maintained when using formatError

Created on 23 Feb 2017  路  3Comments  路  Source: apollographql/react-apollo

I'm using formatError on the server for custom errors:

formatError: err => ({
  message: err.originalError.message,
  status: err.originalError.status,
}),

When an error is thrown, and I look at the response in the network tab of devtools, the error object I get from the server looks like this:

errors: [{
  message: "My error message",
  status: 403
}]

But when apollo throws the error after the client receives it e.g:

try {
  const result = await this.props.randomMutation();
} catch (e) {
  console.log(e.message, e.status);
}

The error details looks like this:

GraphQL error: My error message 
undefined

How do I access all the information from my custom error? Including not having GraphQL error added to the error message?

Cheers :)

question

All 3 comments

You should be able to get at the raw object through error.graphqlErrors. Let me know if that works for you 馃槉

Brilliant, thanks @calebmer!

Also for anyone reading this later, the ql is uppercase e.g. error.graphQLErrors 馃憤

Note for anyone searching this as this has recently changed:

  1. Graphql errors will return error.graphQLErrors array object, first item is the error message.
  2. Network errors error.graphQLErrors will be empty and error.networkError.message is what you want.
Was this page helpful?
0 / 5 - 0 ratings