diff --git a/CHANGELOG.md b/CHANGELOG.md index 21cf209..1dd362f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,18 @@ # Changelog +## v0.3.1 + +### Fixed issues +* Add check and exception when a null or empty client ID is passed to the Oauth/Client class. [Issue #8](https://github.com/rhysnhall/etsy-php-sdk/issues/8) +* Updated handleAcessTokenError() method to check for the existence of 'error_description' in the response body. [Issue #8](https://github.com/rhysnhall/etsy-php-sdk/issues/8) + ## v0.3.0 ### New -* Added `config` property to the Client class. This currently only support the value '404_error' which when set to true will throw an error when a resource returns 404 instead of returning a null value. This value is unset/false by default. +* Added `config` property to the Client class. This currently only supports the value '404_error' which when set to true will throw an error when a resource returns 404 instead of returning a null value. This value is unset/false by default. ### Fixed issues -* Fixed breaking issue with class names in the resource updateRequest method. This issue only relates to Linux environments. [#6] (https://github.com/rhysnhall/etsy-php-sdk/issues/6) +* Fixed breaking issue with class names in the resource updateRequest method. This issue only relates to Linux environments. [#6](https://github.com/rhysnhall/etsy-php-sdk/issues/6) ### Minor notes * Fixed some typos in Client error messages. diff --git a/composer.json b/composer.json index b966528..53679a2 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "rhysnhall/etsy-php-sdk", - "version": "0.3.0", + "version": "0.3.1", "description": "PHP SDK for Etsy API v3.", "type": "library", "keywords": [ diff --git a/src/OAuth/Client.php b/src/OAuth/Client.php index 43e85d4..a6cd261 100644 --- a/src/OAuth/Client.php +++ b/src/OAuth/Client.php @@ -42,11 +42,15 @@ class Client { /** * Create a new instance of Client. * + * @param string $client_id * @return void */ public function __construct( - $client_id + string $client_id ) { + if(is_null($client_id) || !trim($client_id)) { + throw new OAuthException("No client ID found. A valid client ID is required."); + } $this->client_id = $client_id; } @@ -264,8 +268,12 @@ private function handleAcessTokenError(\Exception $e) { $response = $e->getResponse(); $body = json_decode($response->getBody(), false); $status_code = $response->getStatusCode(); + $error_msg = "with error \"{$body->error}\""; + if($body->error_description ?? false) { + $error_msg .= "and message \"{$body->error_description}\""; + } throw new OAuthException( - "Received HTTP status code [$status_code] with error \"{$body->error}\" and message \"{$body->error_description}\" when requesting access token." + "Received HTTP status code [$status_code] {$error_msg} when requesting access token." ); }