Skip to content

Commit

Permalink
Merge pull request #4 from barebitcoin/2023-11-08-errors
Browse files Browse the repository at this point in the history
lib: be more careful when extracting errors
  • Loading branch information
willyfromtheblock committed Dec 30, 2023
2 parents e331f34 + 3630fc6 commit 297c736
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/src/rpcclient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,14 @@ class RPCClient {
),
);
if (response.statusCode == HttpStatus.ok) {
var body = response.data;
if (body['error'] != null) {
var error = body['error']['message'];
var body = response.data as Map<String, dynamic>;
if (body.containsKey('error') && body["error"] != null) {
var error = body['error'];

if (error["message"] is Map<String, dynamic>) {
error = error['message'];
}

throw RPCException(
errorCode: error['code'],
errorMsg: error['message'],
Expand Down

0 comments on commit 297c736

Please sign in to comment.