123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /// JSON-RPC exception
- class JsonRpcException implements Exception {
- String? message;
- int? code;
- dynamic data;
- JsonRpcException({
- this.code,
- this.message,
- this.data,
- });
- @override
- String toString() {
- return 'JSON-RPC Exception: $code $message';
- }
- Map<String, dynamic> toJson() {
- var map = <String, dynamic>{'code': code, 'message': message};
- if (data != null) {
- map['data'] = data;
- }
- return map;
- }
- }
- /// JSON-RPC network exception
- class JsonRpcNetworkException extends JsonRpcException {
- JsonRpcNetworkException(String message, [code = -32000, data])
- : super(message: message);
- }
- /// JSON-RPC Server Error
- class JsonRpcServerError extends JsonRpcException {
- JsonRpcServerError(String message, [code = -32000, data])
- : super(message: message, code: code, data: data);
- JsonRpcServerError.fromJson(Map<String, dynamic> e) : super() {
- if (e.containsKey('message')) {
- message = e['message'];
- }
- if (e.containsKey('code')) {
- code = e['code'];
- }
- if (e.containsKey('data')) {
- data = e['data'];
- }
- }
- }
|