mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-05-04 03:42:19 +00:00
add and use JsonRpcException exception type
This commit is contained in:
parent
8135079046
commit
d4cdbd3455
2 changed files with 30 additions and 12 deletions
lib
|
@ -14,8 +14,8 @@ import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:mutex/mutex.dart';
|
import 'package:mutex/mutex.dart';
|
||||||
|
import 'package:stackwallet/exceptions/json_rpc/json_rpc_exception.dart';
|
||||||
import 'package:stackwallet/networking/socks_socket.dart';
|
import 'package:stackwallet/networking/socks_socket.dart';
|
||||||
import 'package:stackwallet/services/tor_service.dart';
|
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/prefs.dart';
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
|
|
||||||
|
@ -136,9 +136,9 @@ class JsonRPC {
|
||||||
reason: "return req.completer.future.onError: $error\n$stackTrace",
|
reason: "return req.completer.future.onError: $error\n$stackTrace",
|
||||||
);
|
);
|
||||||
return JsonRPCResponse(
|
return JsonRPCResponse(
|
||||||
exception: error is Exception
|
exception: error is JsonRpcException
|
||||||
? error
|
? error
|
||||||
: Exception(
|
: JsonRpcException(
|
||||||
"req.completer.future.onError: $error\n$stackTrace",
|
"req.completer.future.onError: $error\n$stackTrace",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -195,11 +195,8 @@ class JsonRPC {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (proxyInfo == null) {
|
if (proxyInfo == null) {
|
||||||
proxyInfo = TorService.sharedInstance.proxyInfo;
|
throw JsonRpcException(
|
||||||
Logging.instance.log(
|
"JsonRPC.connect failed with useTor=${Prefs.instance.useTor} and proxyInfo is null");
|
||||||
"ElectrumX.connect(): tor detected at $proxyInfo",
|
|
||||||
level: LogLevel.Warning,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// instantiate a socks socket at localhost and on the port selected by the tor service
|
// instantiate a socks socket at localhost and on the port selected by the tor service
|
||||||
|
@ -223,7 +220,7 @@ class JsonRPC {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"JsonRPC.connect(): failed to connect to SOCKS socket at $proxyInfo, $e",
|
"JsonRPC.connect(): failed to connect to SOCKS socket at $proxyInfo, $e",
|
||||||
level: LogLevel.Error);
|
level: LogLevel.Error);
|
||||||
throw Exception(
|
throw JsonRpcException(
|
||||||
"JsonRPC.connect(): failed to connect to SOCKS socket at $proxyInfo, $e");
|
"JsonRPC.connect(): failed to connect to SOCKS socket at $proxyInfo, $e");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +238,7 @@ class JsonRPC {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"JsonRPC.connect(): failed to connect to $host over tor proxy at $proxyInfo, $e",
|
"JsonRPC.connect(): failed to connect to $host over tor proxy at $proxyInfo, $e",
|
||||||
level: LogLevel.Error);
|
level: LogLevel.Error);
|
||||||
throw Exception(
|
throw JsonRpcException(
|
||||||
"JsonRPC.connect(): failed to connect to tor proxy, $e");
|
"JsonRPC.connect(): failed to connect to tor proxy, $e");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,7 +353,7 @@ class _JsonRPCRequest {
|
||||||
Future<void>.delayed(requestTimeout).then((_) {
|
Future<void>.delayed(requestTimeout).then((_) {
|
||||||
if (!isComplete) {
|
if (!isComplete) {
|
||||||
try {
|
try {
|
||||||
throw Exception("_JsonRPCRequest timed out: $jsonRequest");
|
throw JsonRpcException("_JsonRPCRequest timed out: $jsonRequest");
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
completer.completeError(e, s);
|
completer.completeError(e, s);
|
||||||
onTimedOut?.call();
|
onTimedOut?.call();
|
||||||
|
@ -370,7 +367,7 @@ class _JsonRPCRequest {
|
||||||
|
|
||||||
class JsonRPCResponse {
|
class JsonRPCResponse {
|
||||||
final dynamic data;
|
final dynamic data;
|
||||||
final Exception? exception;
|
final JsonRpcException? exception;
|
||||||
|
|
||||||
JsonRPCResponse({this.data, this.exception});
|
JsonRPCResponse({this.data, this.exception});
|
||||||
}
|
}
|
||||||
|
|
21
lib/exceptions/json_rpc/json_rpc_exception.dart
Normal file
21
lib/exceptions/json_rpc/json_rpc_exception.dart
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Stack Wallet.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Cypher Stack
|
||||||
|
* All Rights Reserved.
|
||||||
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
||||||
|
* Generated by Cypher Stack on 2023-05-26
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import 'package:stackwallet/exceptions/sw_exception.dart';
|
||||||
|
|
||||||
|
class JsonRpcException implements SWException {
|
||||||
|
JsonRpcException(this.message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
@override
|
||||||
|
toString() => message;
|
||||||
|
}
|
Loading…
Reference in a new issue