zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 620 forks source link

Don't Understand to Get Error Message #1249

Closed rrifafauzikomara closed 1 year ago

rrifafauzikomara commented 2 years ago

Hi, I have a question about how to get real error message.

I have print the error by default like below.

      print('Rifa 1: ${error}'); // from OperationException
      print('Rifa 2: ${error?.linkException}'); // from LinkException

And this is the result for above code.

flutter: Rifa 1: OperationException(linkException: ServerException(originalException: null, parsedResponse: Response(data: null, errors: [GraphQLError(message: Token has expired., locations: null, path: null, extensions: null)], context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}), response {errors: [{errorType: UnauthorizedException, message: Token has expired.}]})), graphqlErrors: [])
flutter: Rifa 2: ServerException(originalException: null, parsedResponse: Response(data: null, errors: [GraphQLError(message: Token has expired., locations: null, path: null, extensions: null)], context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}), response {errors: [{errorType: UnauthorizedException, message: Token has expired.}]}))

As you can see above, the error is nested. But the point of error is Token has expired.

My question is how to print the Token has expired message only?

And also how to get status code of every error? As you can see above no status code printed.

vincenzopalazzo commented 2 years ago

You should be able to unwrap the exception, but this looks tricky and a smell from an app developer's point of view.

I will work on it to improve this use case, thanks to report it

Mohdx commented 2 years ago

Hello, I'm finding it confusing why OperationException class the graphqlErrors list is empty

I'm testing to throw exception on purpose (for examle "mobile" I change it to "mobil") image

error: OperationException(linkException: ServerException(originalException: null, parsedResponse: Response(data: null, errors: [GraphQLError(message: Variable "$mobile" is not defined by operation "SignIn"., locations: [ErrorLocation(line: 3, column: 18), ErrorLocation(line: 1, column: 1)], path: null, extensions: {category: graphql}), GraphQLError(message: Variable "$mobil" is never used in operation "SignIn"., locations: [ErrorLocation(line: 1, column: 17)], path: null, extensions: {category: graphql})], context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}), response {errors: [{message: Variable "$mobile" is not defined by operation "SignIn"., extensions: {category: graphql}, locations: [{line: 3, column: 18}, {line: 1, column: 1}]}, {message: Variable "$mobil" is never used in operation "SignIn"., extensions: {category: graphql}, locations: [{line: 1, column: 17}]}]})), graphqlErrors: [])

But on GraphQL website the list of errors is not empty image

vincenzopalazzo commented 2 years ago

looks like it is not a graphql error, and also you can not expect to have the same result inside the playground, try with curl!

In addition, these kind of error are some things that we want to improve and throw a generic error, with the possibility to look inside each single one

vincenzopalazzo commented 1 year ago

closing this in favor of this https://github.com/zino-hofmann/graphql-flutter/issues/1270

We can just improve the error handling