0

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.

xadm
  • 8,219
  • 3
  • 14
  • 25
rishabhjainps
  • 410
  • 1
  • 5
  • 14
  • response contains `data` and `errors` (if error exists) props – xadm Feb 03 '21 at 11:16
  • https://github.com/apollographql/apollo-android/blob/96d53ba7ec479e4e2c05dcc456e74031985f0bb6/apollo-api/src/commonMain/kotlin/com/apollographql/apollo/api/Error.kt @xadm Error does not contain HTTPS status. – rishabhjainps Feb 03 '21 at 11:18
  • @xadm it still gives you Message: ${message}, Location: ${locations}, Path: ${path}, but no http status. Status can be helpful to know it sever error or client error. – rishabhjainps Feb 03 '21 at 11:27
  • https://github.com/apollographql/apollo-android/issues?q=is%3Aissue+onHttpError+ – xadm Feb 03 '21 at 11:36

1 Answers1

0

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.

mbonnin
  • 6,893
  • 3
  • 39
  • 55