Skip to content

Commit da70be2

Browse files
add check on instance method that looks into payload for a "responseData" array that contains "status"
if exists, the status is passed as the code for the NotionException. Otherwise, 0
1 parent 44c3cc2 commit da70be2

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Exceptions/NotionException.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@
1010
class NotionException extends LaravelNotionAPIException
1111
{
1212
/**
13-
* @param string $message
14-
* @param array $payload
13+
* @param string $message
14+
* @param array $payload
1515
* @return NotionException
1616
*/
1717
public static function instance(string $message, array $payload = []): NotionException
1818
{
19-
$e = new NotionException($message);
19+
$code = 0;
20+
21+
$responseDataExists = array_key_exists('responseData', $payload);
22+
23+
if ($responseDataExists) {
24+
$responseData = $payload['responseData'];
25+
26+
$code = array_key_exists('status', $responseData) ? $responseData['status'] : 0;
27+
}
28+
29+
$e = new NotionException($message, $code);
2030
$e->payload = $payload;
2131

2232
return $e;
@@ -26,7 +36,7 @@ public static function instance(string $message, array $payload = []): NotionExc
2636
* Handy method to create a NotionException
2737
* from a failed request.
2838
*
29-
* @param Response $response
39+
* @param Response $response
3040
* @return NotionException
3141
*/
3242
public static function fromResponse(Response $response): NotionException

0 commit comments

Comments
 (0)