|
@@ -66,14 +66,20 @@ class JsonRpcClientBase {
|
|
|
}
|
|
|
|
|
|
Future<dynamic> _transmit(JsonRpcRequest request) async {
|
|
|
- final req = await jsonRpcInterceptHost.onRequestTransmit(request);
|
|
|
+ var result;
|
|
|
+ try {
|
|
|
+ final req = await jsonRpcInterceptHost.onRequestTransmit(request);
|
|
|
|
|
|
- String package = jsonEncode(req.toJson());
|
|
|
+ String package = jsonEncode(req.toJson());
|
|
|
|
|
|
- var response = await _postRequest(package);
|
|
|
- if (response == null) throw JsonRpcException(message: "Response Empty");
|
|
|
+ var response = await _postRequest(package);
|
|
|
+ if (response == null) throw JsonRpcException(message: "Response Empty");
|
|
|
|
|
|
- var result = await _handleDecoded(response);
|
|
|
+ result = await _handleDecoded(response);
|
|
|
+ } catch (e) {
|
|
|
+ await _handleHttpRequestError(JsonRpcNetworkException(e.toString()));
|
|
|
+ // throw JsonRpcException(message: "Http error", data: e);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -104,6 +110,12 @@ class JsonRpcClientBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ Future<dynamic> _handleHttpRequestError(JsonRpcNetworkException error) async {
|
|
|
+ final res = await jsonRpcInterceptHost.onHttpRequestError(error);
|
|
|
+
|
|
|
+ throw res;
|
|
|
+ }
|
|
|
+
|
|
|
Future<dynamic> _handleDecoded(Map<String, dynamic> response) async {
|
|
|
final res = await jsonRpcInterceptHost.onResponse(response);
|
|
|
if (res.containsKey('error')) {
|