Skip to content

Commit 9797c74

Browse files
committed
Response: decode error: don't throw, store and provide getter
1 parent 27f54c6 commit 9797c74

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/DatingVIP/API/Response.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Response
3636

3737
private $response = '';
3838

39+
private $error = [];
40+
3941
/**
4042
* Default API response constructor
4143
* - optionally set response.
@@ -81,6 +83,10 @@ public function getRawResponse () {
8183
return $this->response;
8284
}
8385

86+
public function getRawError () {
87+
return $this->error;
88+
}
89+
8490
/**
8591
* Set API response
8692
* - decode from JSON.
@@ -91,6 +97,7 @@ public function getRawResponse () {
9197
*/
9298
public function set($data)
9399
{
100+
$this->error = [];
94101
$result = null;
95102
switch ($this->format) {
96103
case 'nvp':
@@ -103,7 +110,10 @@ public function set($data)
103110
$this->data = empty($data) ? [] : (json_decode($data, true) ?: []);
104111
$result = json_last_error() == JSON_ERROR_NONE;
105112
if (empty ($result)) {
106-
throw new RuntimeException ("Error decoding: " . json_last_error_msg ());
113+
$this->error = [
114+
'error' => json_last_error(),
115+
'msg' => json_last_error_msg(),
116+
];
107117
}
108118
break;
109119
}

0 commit comments

Comments
 (0)