Skip to content

Commit

Permalink
Fix: Throw json string as exeption and add option to disable exeption
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed May 26, 2023
1 parent 6137d00 commit 1a42afd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Classes/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ public function ping(): bool
*
* @param array $response
* @param string|null $additionalText
* @param bool $throwExeptions
* @return array
*/
protected function validateResponse(array $response, ?string $additionalText = null): array
protected function validateResponse(array $response, ?string $additionalText = null, bool $throwExeptions = true): array
{
if (!isset($additionalText)) {
$additionalText = '';
Expand All @@ -282,12 +283,16 @@ protected function validateResponse(array $response, ?string $additionalText = n
if (isset($response['error'])) {
$json = json_encode($response['error']);
$this->mauticLogger->error($additionalText . $json);
throw new Exception($response['error']);
if ($throwExeptions) {
throw new Exception($json);
}
}
if (isset($response['errors'])) {
$json = json_encode($response['errors']);
$this->mauticLogger->error($additionalText . $json);
throw new Exception(implode('<----->',$response['errors']));
if ($throwExeptions) {
throw new Exception($json);
}
}

return $response;
Expand Down

0 comments on commit 1a42afd

Please sign in to comment.