Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork312
-
I'm not sure what I am doing wrong with my error handling using apollo-angular. I have a GraphQL API listenning at localhost:8080 and I make a request that is supposed to return a GraphQL error. The server responds with a HTTP 500 error and the response's body looks like this: {"errors": [ {"detailMessage":"Test error","statusCode":480,"message":"Error details","errorCode":1713213528628 } ],"data": {"requestThatShouldFail":null }}In my Angular app I use functionapolloLinkFactory(httpLink:HttpLink){consterrorLink=onError(({ graphQLErrors, networkError})=>{// Handle errors, but graphQLErrors is always undefined// networkError is an HttpErrorReponse});constlink=httpLink.create({uri:'http://localhost:8080'});return{cache:newInMemoryCache(),link:errorLink.concat(link)});}@NgModule({providers:[{provide:APOLLO_OPTIONS,useFactory:apolloLinkFactory,deps:[HttpLink]}]})exportclassApolloConfigModule{} I used my browser's dev tools and it appears that the HttpErrorResponse returned by Angular's HttpClient's does not match what Appolo Client would expect when parsing the error and calling the error handler. Here is the part of Apollo Client's code that intercepts the error and calls my error handler (you can find it at @apollo/client/link/error/index.js:11): sub=forward(operation).subscribe({next:function(result){// (...)},error:function(networkError){retriedResult=errorHandler({operation:operation,networkError:networkError,//Network errors can return GraphQL errors on for example a 403graphQLErrors:networkError&&// <-- Here my network error should be parsed to extract GraphQL errorsnetworkError.result&&networkError.result.errors,forward:forward,});if(retriedResult){retriedSub=retriedResult.subscribe({next:observer.next.bind(observer),error:observer.error.bind(observer),complete:observer.complete.bind(observer),});return;}observer.error(networkError);},complete:function(){// (...)},}); The problem is the HttpErrorResponse that is emitted does not have the It worked when I tried using |
BetaWas this translation helpful?Give feedback.