From fb7d14c8a6cdf7292465522cde18343b573a57b6 Mon Sep 17 00:00:00 2001 From: Mark Ogilvie Date: Tue, 13 Jul 2021 10:13:56 +0100 Subject: [PATCH 1/4] Remove copied content from Contact, add ApiKeyName --- src/Modules/ChartOfAccounts.php | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/Modules/ChartOfAccounts.php b/src/Modules/ChartOfAccounts.php index e464bfa..817325a 100644 --- a/src/Modules/ChartOfAccounts.php +++ b/src/Modules/ChartOfAccounts.php @@ -2,7 +2,6 @@ namespace Webleit\ZohoBooksApi\Modules; use Webleit\ZohoBooksApi\Client; -use Webleit\ZohoBooksApi\Modules\Contacts\ContactPersons; /** * Class ChartOfAccounts @@ -10,28 +9,15 @@ */ class ChartOfAccounts extends Module { - /** - * @var ContactPersons - */ - public $contactpersons; - - public function __construct(Client $client) - { - parent::__construct($client); - - $this->contactpersons = new ContactPersons($client); - } /** - * @param $id - * @return \Illuminate\Support\Collection + * Return Zoho API Key Name for Chart of Accounts */ - public function getContactPersons($id) + public function getApiKeyName() { - $className = $this->getModelClassName() . '\\Person'; - return $this->getPropertyList('contactpersons', $id, $className, 'contact_persons', $this->contactpersons); + return 'account_id'; } - + /** * @param $id * @return bool @@ -49,4 +35,4 @@ public function markAsInactive($id) { return $this->markAs('inactive', $id); } -} \ No newline at end of file +} From 560af89dc4efb3a88659b5e9739f3f370e0462cb Mon Sep 17 00:00:00 2001 From: Mark Ogilvie Date: Tue, 13 Jul 2021 11:53:21 +0100 Subject: [PATCH 2/4] Return the package ErrorResponseException Possible solution to "In processResult ErrorResponseException is never thrown if there is a Guzzle Exception" #59 --- src/Client.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 332fa50..7b55566 100644 --- a/src/Client.php +++ b/src/Client.php @@ -197,6 +197,7 @@ public function call(string $uri, string $method, array $data = [], array $rawDa $this->httpClient->$method($this->getUrl() . $uri, $options) ); } catch (ClientException $e) { + // Retry? if ($e->getCode() === 401 && ! $this->retriedRefresh) { $this->oAuthClient->refreshAccessToken(); @@ -205,7 +206,11 @@ public function call(string $uri, string $method, array $data = [], array $rawDa return $this->call($uri, $method, $data); } - throw $e; + // Get the Zoho error code and message instead of the GuzzleError + preg_match('/"code":(\d*)/', $e->getMessage(), $zohoErrorCode); + preg_match('/"message":(.*)/', $e->getMessage(), $zohoErrorMessage); + + throw new ErrorResponseException($zohoErrorMessage[1], $zohoErrorCode[1], $e); } } From 766761a04eebb4fc742deb9b631587bc9ab50eae Mon Sep 17 00:00:00 2001 From: Mark Ogilvie Date: Tue, 13 Jul 2021 13:06:21 +0100 Subject: [PATCH 3/4] Throw error response exception on 400 exceptions --- src/Client.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 7b55566..664180e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -206,11 +206,15 @@ public function call(string $uri, string $method, array $data = [], array $rawDa return $this->call($uri, $method, $data); } - // Get the Zoho error code and message instead of the GuzzleError - preg_match('/"code":(\d*)/', $e->getMessage(), $zohoErrorCode); - preg_match('/"message":(.*)/', $e->getMessage(), $zohoErrorMessage); - - throw new ErrorResponseException($zohoErrorMessage[1], $zohoErrorCode[1], $e); + // Throw an error response exception on 400 Bad Request to return the Zoho error message. + if (400 === $e->getCode()) { + preg_match('/"code":(\d*)/', $e->getMessage(), $zohoErrorCode); + preg_match('/"message":(.*)/', $e->getMessage(), $zohoErrorMessage); + + throw new ErrorResponseException($zohoErrorMessage[1], $zohoErrorCode[1], $e); + } + + throw $e; } } From e2b71b6415b7067c30e88ccb89412c2eb869383e Mon Sep 17 00:00:00 2001 From: Mark Ogilvie Date: Tue, 13 Jul 2021 14:06:30 +0100 Subject: [PATCH 4/4] Remove } from error message or end of line. --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 664180e..3355014 100644 --- a/src/Client.php +++ b/src/Client.php @@ -209,7 +209,7 @@ public function call(string $uri, string $method, array $data = [], array $rawDa // Throw an error response exception on 400 Bad Request to return the Zoho error message. if (400 === $e->getCode()) { preg_match('/"code":(\d*)/', $e->getMessage(), $zohoErrorCode); - preg_match('/"message":(.*)/', $e->getMessage(), $zohoErrorMessage); + preg_match('/"message":(.*)[}|\n]/', $e->getMessage(), $zohoErrorMessage); throw new ErrorResponseException($zohoErrorMessage[1], $zohoErrorCode[1], $e); }