Skip to content

Commit bb8af48

Browse files
committed
Include raw request response in the exception for easier debugging.
1 parent 1566c36 commit bb8af48

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/Exceptions/PrintfulException.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@
99
*/
1010
class PrintfulException extends Exception
1111
{
12+
/**
13+
* Last response from API that triggered this exception
14+
*
15+
* @var string
16+
*/
17+
public $rawResponse;
1218
}

src/PrintfulApiClient.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,15 @@ private function request($method, $path, array $params = [], $data = null)
170170
$this->lastResponse = $response = json_decode($this->lastResponseRaw, true);
171171

172172
if (!isset($response['code'], $response['result'])) {
173-
throw new PrintfulException('Invalid API response');
173+
$e = new PrintfulException('Invalid API response');
174+
$e->rawResponse = $this->lastResponseRaw;
175+
throw $e;
174176
}
175177
$status = (int)$response['code'];
176178
if ($status < 200 || $status >= 300) {
177-
throw new PrintfulApiException((string)$response['result'], $status);
179+
$e = new PrintfulApiException((string)$response['result'], $status);
180+
$e->rawResponse = $this->lastResponseRaw;
181+
throw $e;
178182
}
179183
return $response['result'];
180184
}

0 commit comments

Comments
 (0)