Skip to content
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

Apollo Kotlin 4 - Receiving 403 Error Instead of GraphQL Error Response on Incorrect Login #6169

Open
Anolcera opened this issue Sep 30, 2024 · 2 comments

Comments

@Anolcera
Copy link

Question

I'm working on a Compose Multiplatform project using Apollo Kotlin 4 for GraphQL communication. When I attempt to log in with incorrect credentials, the server sends a JSON response containing a GraphQL error:

{ "errors": [ { "extensions": { "reason": "Incorrect username or password.", "show_resend": false } } ] }

However, my Apollo client is throwing an ApolloNetworkException with the message "Http request failed with status code 403" and doesn't provide access to the actual GraphQL error details.

Interestingly, when I test the same mutation in Postman, it correctly displays the GraphQL error response.

My question is:

What could be causing this discrepancy between the Apollo client and Postman? Is there a configuration issue on the client or server side? How can I properly catch and handle this GraphQL error response in my Apollo Kotlin code so I can display the "Incorrect username or password" message to the user?

@martinbonnin
Copy link
Contributor

martinbonnin commented Sep 30, 2024

Hi 👋 It's a long story but any non-200 response isn't parsed as a GraphQL response. This is something the GraphQL over HTTP effort aims to fix.
If your server is using the new application/graphql-response+json content-type, we can fix that in Apollo Kotlin, this is something that I've been wanting to do for a while now. If not, you'll have to go through some extra hoops of using exposeHttpErrorBody (see this stack overflow answer).

@Anolcera
Copy link
Author

Anolcera commented Oct 1, 2024

Yes the server is using that so I'm just waiting for your PR to be merged. Thank you a LOT

@martinbonnin martinbonnin added this to the 4.0.2 milestone Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants