Skip to content

Commit

Permalink
throw JsonException if cannot parse json, and handle it as provision …
Browse files Browse the repository at this point in the history
…function error
  • Loading branch information
Roussetos Karafyllakis committed Jan 8, 2025
1 parent e8abb38 commit 4d2a0bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"upmind/enhance-sdk": "^10",
"giggsey/libphonenumber-for-php-lite": "^8",
"ext-curl": "*",
"ext-json": "*",
"ext-soap": "*"
},
"require-dev": {
Expand Down
9 changes: 8 additions & 1 deletion src/Webuzo/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ public function makeRequest(
*/
private function parseResponseData(string $response): array
{
$parsedResult = json_decode($response, true);
try {
$parsedResult = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
throw ProvisionFunctionError::create('Failed to parse response data', $e)
->withData([
'response' => $response,
]);
}

if ($error = $this->getResponseErrorMessage($parsedResult)) {
throw ProvisionFunctionError::create($error)
Expand Down

0 comments on commit 4d2a0bf

Please sign in to comment.