Skip to content

Commit fcfaf94

Browse files
committed
feat: pass error data for debugging purpose with exception
1 parent 58743d0 commit fcfaf94

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

src/Client/EnvatoClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function makeApiCall($method, $url, $options)
108108

109109
return $this->parseResponse($response);
110110
} catch (Exception $e) {
111-
LaravelEnvatoUtils::handleEnvatoException($e);
111+
LaravelEnvatoUtils::handleEnvatoException($e, $options);
112112
}
113113
}
114114

src/Exceptions/EnvatoException.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ class EnvatoException extends Exception
1212
*/
1313
public $error;
1414

15+
/**
16+
* @var array
17+
*/
18+
public $errorData;
19+
1520
/**
1621
* @param string $error
1722
* @param string $message
1823
* @param int $code
24+
* @param array $errorData
1925
* @param Throwable|null $previous
2026
*/
21-
public function __construct($error, $message = '', $code = 0, Throwable $previous = null)
27+
public function __construct($error, $message = '', $code = 0, Throwable $previous = null, $errorData = [])
2228
{
2329
parent::__construct($message, $code, $previous);
2430
$this->error = $error;
31+
$this->errorData = $errorData;
2532
}
2633
}

src/Managers/AuthManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ public function refreshToken()
104104
'base_uri' => config('laravel-envato.api_endpoint'),
105105
]);
106106

107+
$options = ['form_params' => $params];
108+
107109
try {
108-
$response = $client->request('POST', 'token', [
109-
'form_params' => $params,
110-
]);
110+
$response = $client->request('POST', 'token', $options);
111111
} catch (Exception $e) {
112-
LaravelEnvatoUtils::handleEnvatoException($e);
112+
LaravelEnvatoUtils::handleEnvatoException($e, $options);
113113
}
114114

115115
if ($response->getStatusCode() === 200) {

src/Utils/LaravelEnvatoUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LaravelEnvatoUtils
1616
* @throws EnvatoException
1717
* @throws EnvatoRateLimitException
1818
*/
19-
public static function handleEnvatoException($e)
19+
public static function handleEnvatoException($e, $errorData = [])
2020
{
2121
/** @var ClientException $e */
2222
if ($e->getCode() === Response::HTTP_TOO_MANY_REQUESTS) {
@@ -26,7 +26,7 @@ public static function handleEnvatoException($e)
2626
$response = json_decode($e->getResponse()->getBody()->getContents(), true);
2727

2828
if (isset($response['error']) and isset($response['error_description'])) {
29-
throw new EnvatoException($response['error'], $response['error_description'], $e->getCode(), $e);
29+
throw new EnvatoException($response['error'], $response['error_description'], $e->getCode(), $e, $errorData);
3030
}
3131

3232
throw $e;

0 commit comments

Comments
 (0)