So this might have been super obvious to other folks out there but it
wasn't for me. You can get at the original GraphQLResult
<https://aws-amplify.github.io/amplify-js/api/interfaces/graphqlresult.html> by
looking at the *error.promise* and *error.rejection*. So in your handleError
method:
---------------------
isGraphQLResult(rejection: any): boolean {
return rejection !== undefined && (rejection.data !== undefined ||
rejection.errors !== undefined);
}
handleError(error: any): void {
if (error !== undefined && this.isGraphQLResult(error.rejection)) {
const graphqlResult: GraphQLResult = error.rejection as GraphQLResult;
// handle the graphqlResult
}
}
---------------------
Honestly didn't know that *error.promise* and *error.rejection* were even
there ... I guess I missed the memo on that one.
On Saturday, January 2, 2021 at 9:18:41 AM UTC-8 Marcus Malcom wrote:
> I originally posted this question here: Angular Amplify Error Handler -
> GraphQL API Calls
> <https://github.com/aws-amplify/amplify-js/discussions/7474>. The basics
> are:
>
> 1. I have a global error handler that is working for calls to an API
> service
> 2. When I do a try/catch, I get an error object that *data* and *errors
> *as members (the catch is getting an object of this type: GraphQLResult
>
> <https://aws-amplify.github.io/amplify-js/api/interfaces/graphqlresult.html>
> )
> 3. The error object I receive in my error handler is not a
> GraphQLResult
>
> <https://aws-amplify.github.io/amplify-js/api/interfaces/graphqlresult.html>.
> Instead it is an error object that has an error message, GraphQLResult
> converted to a string and stack trace
>
> I'm trying to figure out if there's a better way to do this, any help?
>
> Thank you!
>
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/angular/98d63d65-8e07-4bde-99bd-b5760658b495n%40googlegroups.com.