Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -205,6 +206,14 @@ public function call(string $uri, string $method, array $data = [], array $rawDa
return $this->call($uri, $method, $data);
}

// 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":(.*)[}|\n]/', $e->getMessage(), $zohoErrorMessage);

throw new ErrorResponseException($zohoErrorMessage[1], $zohoErrorCode[1], $e);
}

throw $e;
}
}
Expand Down