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

custom library-level exceptions #319

Closed
micimize opened this issue May 31, 2019 · 4 comments
Closed

custom library-level exceptions #319

micimize opened this issue May 31, 2019 · 4 comments

Comments

@micimize
Copy link
Collaborator

As pointed out in #177

we could solve this by creating our own kind of exceptions so that we can handle them cleaner internally.

It would also make it easier / possible for users to have different logic for different errors, i.e. ignore network related issues when using the cache.

Worth noting that without something like #201, it will be easy for a user making heavy use of the offline queue to shoot themselves in the foot by pretending mutations succeeded when they didn't and will never run again.

@micimize
Copy link
Collaborator Author

@mainawycliffe @HofmannZ I'm working on this right now, and currently looking at wrapping our graphql errors in a container similar to ApolloError.

Here's the general idea so far:

// in graphql/lib/src/exceptions/exceptions.dart
class OperationException implements Exception {
  List<GraphQLError> graphqlErrors = [];

  // generalize to include cache error, etc
  ClientException clientException; 
}


// in graphql/lib/src/core/query_result.dart
class QueryResult {
  // ...

  // in place of List<GraphQLError> errors;
  OperationException exception;
  /// Whether the response includes any graphql errors
  bool get hasErrors => !(exception == null);
 
  /// Whether the response includes any graphql errors
  bool get hasGraphqlErrors => exception?.graphqlErrors?.isNotEmpty ?? false;
 
  /// graphql errors in the exception, if any
  List<GraphQLError> get graphqlErrors => exception?.graphqlErrors;

  // ...
}

decisions / trade-offs:

  • dart makes a semantic distinction between errors and exceptions - what we're dealing with on the client are mostly exceptions as they are meant to be handed rather than avoided.
  • I don't think having all these *Errors methods is good - need to come up with a better api for handling multi-source errors. Maybe the thing to do is to not obscure the exception at all, replace hasError with hasException, and just let the user handle it like apollo does.

@micimize
Copy link
Collaborator Author

closed by #393

Open Scrum automation moved this from To do to Done Dec 20, 2019
@HofmannZ
Copy link
Member

🎉 This issue has been resolved in version 3.0.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@HofmannZ
Copy link
Member

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Open Scrum
  
Done
Development

No branches or pull requests

2 participants