Skip to content

Commit 3ed87b5

Browse files
authored
Save error code from response & invalid wallet specified (#71)
* save error code from response * change identation
1 parent 38f4c35 commit 3ed87b5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Content.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ function createWalletContent(){
227227
$walletInfo = $bitcoind->getwalletinfo();
228228
$balances = $bitcoind->getbalances();
229229
}catch(\Exception $e){
230-
$error = "Wallet disabled!";
230+
if ($e->getCode() == -18) {
231+
$error = "Invalid wallet specified!";
232+
} else {
233+
$error = "Wallet disabled!";
234+
}
231235
return "";
232236
}
233237

src/jsonRPCClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class jsonRPCClient
2323
// Information and debugging
2424
public $status;
2525
public $error;
26+
public $errorCode;
2627
public $raw_response;
2728
public $response;
2829

@@ -59,6 +60,7 @@ public function __call($method, $params)
5960
{
6061
$this->status = null;
6162
$this->error = null;
63+
$this->errorCode = null;
6264
$this->raw_response = null;
6365
$this->response = null;
6466

@@ -135,6 +137,7 @@ public function __call($method, $params)
135137

136138
if($this->status === 500 && $this->response['error']) {
137139
$this->error = $this->response['error']['message'];
140+
$this->errorCode = $this->response['error']['code'];
138141
}elseif ($this->status !== 200) {
139142
// If bitcoind didn't return a nice error message, we need to make our own
140143
switch ($this->status) {
@@ -153,7 +156,7 @@ public function __call($method, $params)
153156
}
154157

155158
if ($this->error) {
156-
throw new \Exception($this->error);
159+
throw new \Exception($this->error, $this->errorCode);
157160
}
158161

159162
return $this->response['result'];

0 commit comments

Comments
 (0)