You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
In my Angular app I use onError with a callback function but I only get a network error, no GraphQL errors:
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 result field, causing graphQLErrors to be left undefined.
It worked when I tried using createHttpLink from Apollo Client instead of apollo-angular's HttpLink.create(), but then it doesn't use an Angular HttpClient which I need because I use interceptors.
Am I doing something wrong? Or should apollo-angular's HttpLinkHandler pre-parse the HttpErrorResponse so it looks more like what ApolloClient expects, instead of sending it as-is?
Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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:
In my Angular app I use
onError
with a callback function but I only get a network error, no GraphQL errors: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):
The problem is the HttpErrorResponse that is emitted does not have the
result
field, causinggraphQLErrors
to be left undefined.It worked when I tried using
createHttpLink
from Apollo Client instead of apollo-angular'sHttpLink.create()
, but then it doesn't use an Angular HttpClient which I need because I use interceptors.Am I doing something wrong? Or should apollo-angular's HttpLinkHandler pre-parse the HttpErrorResponse so it looks more like what ApolloClient expects, instead of sending it as-is?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions