-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed HTTP response does not contain exception #6271
Comments
Thanks for sending this. This is due to the support for This is an unfortunate behaviour change, alas I haven't found a way to provide a better update path and could probably be considered a bugfix. If you want to restore the throwing behaviour, you can use an PS: you can read more details about the new content-type in the GraphQL over HTTP spec |
@martinbonnin Thank you Martin! I was checking release notes but I totally missed this part. I will try to implement the interceptor. |
Hmm looking at the it again I don't think I implemented I did not read whole GraphQL over HTTP spec specification but I would expect that if server is not returning |
I'd say the key is using .addInterceptor(object : ApolloInterceptor {
override fun <D : Operation.Data> intercept(
request: ApolloRequest<D>,
chain: ApolloInterceptorChain,
): Flow<ApolloResponse<D>> {
return chain.proceed(request).onEach {
val httpInfo = it.executionContext[HttpInfo]
if (httpInfo != null && httpInfo.statusCode !in 200..299) {
throw ApolloHttpException(httpInfo.statusCode, httpInfo.headers, null, "HTTP request failed")
}
}
}
})
I'd recommend your server folks to include something in the GraphQL errors: {
"errors": [
{
"message": "AuthorizationFailed",
"extensions": {
"code": 401 // or something else, doesn't have to match HTTP codes.
}
}
]
} That can be used to do the error handling at the GraphQL layer instead of peeking into HTTP (but peeking into HTTP should work too) Hope this helps! |
@jiri-muller anything else we can help with here? |
Closing for now, please leave a message if you want us to revisit |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better. |
Version
4.1.0
Summary
There is no exception in response when HTTP request fails (i.e 401).
Response in 4.1.0
Response in 4.0.1
Steps to reproduce the behavior
Logs
The text was updated successfully, but these errors were encountered: