forked from zino-hofmann/graphql-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): library-level exception handling
BREAKING CHANGE: replaces result.errors with result.exception
- Loading branch information
Showing
7 changed files
with
71 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
import './_base_exceptions.dart' as _b; | ||
import 'package:graphql/src/exceptions/io_network_exception.dart' as _n; | ||
|
||
export './_base_exceptions.dart' hide translateFailure; | ||
export './graphql_error.dart'; | ||
export './operation_exception.dart'; | ||
export './network_exception_stub.dart' | ||
if (dart.library.io) './io_network_exceptions.dart'; | ||
if (dart.library.io) './io_network_exceptions.dart' | ||
hide translateNetworkFailure; | ||
|
||
_b.ClientException translateFailure(dynamic failure) { | ||
return _n.translateNetworkFailure(failure) ?? _b.translateFailure(failure); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 14 additions & 9 deletions
23
packages/graphql/lib/src/exceptions/network_exception_stub.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
import './base_exceptions.dart' show ClientException; | ||
import 'package:http/http.dart' as http; | ||
|
||
typedef VoidCallback = void Function(); | ||
import './_base_exceptions.dart' show ClientException; | ||
|
||
class NetworkException implements ClientException { | ||
covariant Exception wrappedException; | ||
|
||
final String message; | ||
|
||
final String targetAddress; | ||
final int targetPort; | ||
final Uri uri; | ||
|
||
NetworkException({ | ||
this.wrappedException, | ||
this.message, | ||
this.targetAddress, | ||
this.targetPort, | ||
this.uri, | ||
}); | ||
|
||
String toString() => | ||
'Failed to connect to $targetAddress:$targetPort: $message'; | ||
String toString() => 'Failed to connect to $uri: $message'; | ||
} | ||
|
||
void translateExceptions(VoidCallback block) => block(); | ||
NetworkException translateNetworkFailure(dynamic failure) { | ||
if (failure is http.ClientException) { | ||
return NetworkException( | ||
wrappedException: failure, | ||
message: failure.message, | ||
uri: failure.uri, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters