How to get HTTP status code in GraphQL apollo-android client

1.7k views Asked by At

I am using apollo client https://github.com/apollographql/apollo-android to query Graphql API. In Graphql Server, we are returning with HTTPS status

return Response.status( Status.BAD_REQUEST ).entity( exception.getMessage() ).build();

How can I get HTTPS status code in response at client side?

Client code

ApolloCall<T> apolloCall = apolloClient.query( query );
Response<T> response = Rx2Apollo.from( apolloCall ).onErrorReturn( throwable -> null ).blockingFirst();

I majorly want to know whether the error is client exception or server exceeption.

1

There are 1 answers

0
mbonnin On

You can remove the .onErrorReturn( throwable -> null ) part and the HTTP error will be returned in onError as a ApolloHttpException on which you can call .code() to get the HTTP code.