Skip to content

Commit

Permalink
Fix empty errors message
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Sep 10, 2024
1 parent a2f3713 commit 6c6b723
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Client/ActiveCampaignResourceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ public function create(ResourceInterface $resource): CreateResourceResponseInter

throw new NotFoundHttpException($errorResponse['message']);
case 422:
/** @var array{errors: array{title: string, detail: string, code: string, source: array{pointer: string}}} $errorResponse */
/** @var array{errors: array{title: string, detail: string, code: string, source: array{pointer: string}}|null} $errorResponse */
$errorResponse = json_decode($response->getBody()->getContents(), true, 512, \JSON_THROW_ON_ERROR);
/** @var string[] $titles */
$titles = array_column($errorResponse['errors'], 'title');

throw new UnprocessableEntityHttpException(implode('; ', $titles));
$errorMessage = '';
if (is_array($errorResponse['errors'])) {
/** @var string[] $titles */
$titles = array_column($errorResponse['errors'], 'title');
$errorMessage = implode('; ', $titles);
}

throw new UnprocessableEntityHttpException($errorMessage);
default:
throw new HttpException($statusCode, $response->getReasonPhrase(), null, $response->getHeaders());
}
Expand Down Expand Up @@ -198,12 +202,16 @@ public function update(int $activeCampaignResourceId, ResourceInterface $resourc

throw new NotFoundHttpException($errorResponse['message']);
case 422:
/** @var array{errors: array{title: string, detail: string, code: string, source: array{pointer: string}}} $errorResponse */
/** @var array{errors: array{title: string, detail: string, code: string, source: array{pointer: string}}|null} $errorResponse */
$errorResponse = json_decode($response->getBody()->getContents(), true, 512, \JSON_THROW_ON_ERROR);
/** @var string[] $titles */
$titles = array_column($errorResponse['errors'], 'title');

throw new UnprocessableEntityHttpException(implode('; ', $titles));
$errorMessage = '';
if (is_array($errorResponse['errors'])) {
/** @var string[] $titles */
$titles = array_column($errorResponse['errors'], 'title');
$errorMessage = implode('; ', $titles);
}

throw new UnprocessableEntityHttpException($errorMessage);
default:
throw new HttpException($statusCode, $response->getReasonPhrase(), null, $response->getHeaders());
}
Expand Down

0 comments on commit 6c6b723

Please sign in to comment.