https://kotlinlang.org logo
#apollo-kotlin
Title
# apollo-kotlin
p

Parijat Shah

02/22/2023, 10:44 PM
Any reason why Apollo client ( v3.7.4) throws ApolloNetworkException when response code is 401
m

mbonnin

02/22/2023, 11:02 PM
What would you expect instead?
p

Parijat Shah

02/22/2023, 11:07 PM
I could handle it or AuthException
m

mbonnin

02/22/2023, 11:08 PM
i'd recommend you handle this at the HttpInterceptor level
p

Parijat Shah

02/22/2023, 11:08 PM
I just wanted to understand the rational. I am already working with it.
m

mbonnin

02/22/2023, 11:08 PM
This way you can retry transparently
p

Parijat Shah

02/22/2023, 11:08 PM
That make sense.
m

mbonnin

02/22/2023, 11:09 PM
All exceptions inherit from ApolloExcption so that it's easier to know what can happen
I'm not even sure there's a MPP AuthException?
p

Parijat Shah

02/22/2023, 11:11 PM
There isn't . I meant something on those lines .. ApolloAuthException
m

mbonnin

02/22/2023, 11:11 PM
Some servers handle auth at the GraphQl layer
There's no concept of Authentication in GraphQL, it's a HTTP thing really
It's all server dependant
p

Parijat Shah

02/22/2023, 11:14 PM
I agree. I guess only way to propagate 401 is throwing exception and it makes more sense to handle it at HttpInterceptor level since it is actually HTTP thing
m

mbonnin

02/22/2023, 11:15 PM
Exactly!
I think if you really want to you should be able to get the HTTP code from the ApolloNetworkException (there should be a ApolloHttpException somewhere in 'cause' or so that contains the status code)
Not 100% sure about the details as I'm on mobile right now but in all cases, HTTP is the good place to handle this
p

Parijat Shah

02/22/2023, 11:19 PM
Yes. I am going to handle at Http level. Thank you for your inputs Martin.
m

mbonnin

02/22/2023, 11:27 PM
Sure thing!
8 Views