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 :)
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:
error.graphQLErrors array object, first item is the error message.error.graphQLErrors will be empty and error.networkError.message is what you want.