Skip to content

Commit a77d239

Browse files
committed
fix: handle has response exception
1 parent fcfaf94 commit a77d239

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.2.5|^8.0",
20+
"ext-json": "*",
2021
"guzzlehttp/guzzle": "^7.4",
2122
"illuminate/support": "^9.0|^8.0|^7.0|^6.0"
2223
},

src/Utils/LaravelEnvatoUtils.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use GuzzleHttp\Exception\ClientException;
7+
use GuzzleHttp\Exception\RequestException;
78
use Illuminate\Http\Response;
89
use InfyOmLabs\LaravelEnvato\Exceptions\EnvatoException;
910
use InfyOmLabs\LaravelEnvato\Exceptions\EnvatoRateLimitException;
@@ -23,10 +24,14 @@ public static function handleEnvatoException($e, $errorData = [])
2324
throw new EnvatoRateLimitException(intval($e->getResponse()->getHeader('Retry-After')[0]));
2425
}
2526

26-
$response = json_decode($e->getResponse()->getBody()->getContents(), true);
27+
if ($e instanceof RequestException) {
28+
if ($e->hasResponse()) {
29+
$response = json_decode($e->getResponse()->getBody()->getContents(), true);
2730

28-
if (isset($response['error']) and isset($response['error_description'])) {
29-
throw new EnvatoException($response['error'], $response['error_description'], $e->getCode(), $e, $errorData);
31+
if (isset($response['error']) and isset($response['error_description'])) {
32+
throw new EnvatoException($response['error'], $response['error_description'], $e->getCode(), $e, $errorData);
33+
}
34+
}
3035
}
3136

3237
throw $e;

0 commit comments

Comments
 (0)