apollo-ios: How to handle errors correctly
Hi, I am currently on the stage of migrating from 0.33 -> 0.36. Gone through all the provided documentation, but I am still confused on what would be the correct way of handling errors(also read the suggested article: https://medium.com/@sachee/200-ok-error-handling-in-graphql-7ec869aec9bc).
Before going to write this question, I just wanted to give it a try myself.
One of the most important use cases related to error handling is that we want to cover the case when a auth token expires on the backend, which results in an error when performing the next app query or mutation. At this stage, we want to catch the error, perform automatically a relogin(call login
mutation), which basically will return a new auth token and after all that re-execute the failed request(query/mutation).
As far as I managed to understand, the best way to do this is through ApolloErrorInterceptor
, which I basically did. I created a custom ApolloErrorInterceptor
, returned it in InterceptorProvider.additionalErrorInterceptor
.
The first problem I met is that it seems that not absolutely all errors get through this interceptor. Which left me without ideas on how to continue, but since this new apollo sdk approach is pretty fresh, I also left some space to consider it might be a bug, full stop
.
Now my question is: what is the correct way of handling errors? Can we improve the documentation to provide more examples about it?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (10 by maintainers)
I will try to collect the information tomorrow;)
OK, that’s merged - is there anything else here I can help clarify, or do you mind if we close this out?
@odanu @RolandasRazma Added some docs on the additional error interceptor to #1484