diff --git a/src/Client/EnvatoClient.php b/src/Client/EnvatoClient.php index 1a92ed4..e0c06f0 100644 --- a/src/Client/EnvatoClient.php +++ b/src/Client/EnvatoClient.php @@ -108,7 +108,7 @@ private function makeApiCall($method, $url, $options) return $this->parseResponse($response); } catch (Exception $e) { - LaravelEnvatoUtils::handleEnvatoException($e); + LaravelEnvatoUtils::handleEnvatoException($e, $options); } } diff --git a/src/Exceptions/EnvatoException.php b/src/Exceptions/EnvatoException.php index 2868260..26d78f2 100644 --- a/src/Exceptions/EnvatoException.php +++ b/src/Exceptions/EnvatoException.php @@ -12,15 +12,22 @@ class EnvatoException extends Exception */ public $error; + /** + * @var array + */ + public $errorData; + /** * @param string $error * @param string $message * @param int $code + * @param array $errorData * @param Throwable|null $previous */ - public function __construct($error, $message = '', $code = 0, Throwable $previous = null) + public function __construct($error, $message = '', $code = 0, Throwable $previous = null, $errorData = []) { parent::__construct($message, $code, $previous); $this->error = $error; + $this->errorData = $errorData; } } diff --git a/src/Managers/AuthManager.php b/src/Managers/AuthManager.php index 49bd8b1..8e4fd14 100644 --- a/src/Managers/AuthManager.php +++ b/src/Managers/AuthManager.php @@ -104,12 +104,12 @@ public function refreshToken() 'base_uri' => config('laravel-envato.api_endpoint'), ]); + $options = ['form_params' => $params]; + try { - $response = $client->request('POST', 'token', [ - 'form_params' => $params, - ]); + $response = $client->request('POST', 'token', $options); } catch (Exception $e) { - LaravelEnvatoUtils::handleEnvatoException($e); + LaravelEnvatoUtils::handleEnvatoException($e, $options); } if ($response->getStatusCode() === 200) { diff --git a/src/Utils/LaravelEnvatoUtils.php b/src/Utils/LaravelEnvatoUtils.php index f582a2c..3ddee79 100644 --- a/src/Utils/LaravelEnvatoUtils.php +++ b/src/Utils/LaravelEnvatoUtils.php @@ -16,7 +16,7 @@ class LaravelEnvatoUtils * @throws EnvatoException * @throws EnvatoRateLimitException */ - public static function handleEnvatoException($e) + public static function handleEnvatoException($e, $errorData = []) { /** @var ClientException $e */ if ($e->getCode() === Response::HTTP_TOO_MANY_REQUESTS) { @@ -26,7 +26,7 @@ public static function handleEnvatoException($e) $response = json_decode($e->getResponse()->getBody()->getContents(), true); if (isset($response['error']) and isset($response['error_description'])) { - throw new EnvatoException($response['error'], $response['error_description'], $e->getCode(), $e); + throw new EnvatoException($response['error'], $response['error_description'], $e->getCode(), $e, $errorData); } throw $e;