gql-dart / gql

Libraries supporting GraphQL in Dart
MIT License
268 stars 124 forks source link

HttpLinkServerException (ServerException) contains parsedResponse #380

Closed RobertBrunhage closed 1 year ago

RobertBrunhage commented 1 year ago

When looking at the docs for HttpLinkServerException it has the following text:

/// Exception occurring when network fails
/// or parsed response is missing both `data` and `errors`. <--- parsedResponse should have missing data and errors

Is this true? I get exceptions thrown with HttpLinkServerException that contains the parsedResponse.

In this case it has the following information:

// the below code is thrown when we catch for `HttpLinkServerException`
ServerException(
  originalException: null, 
  parsedResponse: Response(
    data: null, errors: [GraphQLError(message: unauthenticated, locations: null, path: null, extensions: {code: AUTHENTICATION_ERROR, statusCode: 401})], context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}), response {errors: [{message: unauthenticated, extensions: {code: AUTHENTICATION_ERROR, statusCode: 401}}]}
  )
)

I don't have a good way currently to reproduce this more than seeing it logged to Sentry. I could also misunderstand this, so would love some input!

knaeckeKami commented 1 year ago

It is also thrown when the Status code is >= 300. see https://github.com/gql-dart/gql/blob/master/links/gql_http_link/lib/src/link.dart#L80

This is probably what you are running into?

RobertBrunhage commented 1 year ago

Oh, missed that completely! Thank you, will take another look!

RobertBrunhage commented 1 year ago

Looking at that documentation it seems like it should have the statusCode but that seems to be null. Is that intended?

The statusCode can be accessed through the GraphQLError though, as a workaround currently but is not the nicest.

knaeckeKami commented 1 year ago

The addition of the status code in the server exception was a recent addition in https://github.com/gql-dart/gql/pull/375

It's only available in the latest alpha 0.4.6-alpha+1672756470520 (should be safe to use though, will bump it to stable soon)

RobertBrunhage commented 1 year ago

Got it, thanks @knaeckeKami for all the quick responses and hard work!

Will close this.