Skip to content

Commit

Permalink
Merge pull request #103 from luka-papez/fix/annoying-exception-on-emp…
Browse files Browse the repository at this point in the history
…ty-response

fix(developer-experience): prevent an annoying exception from being raised when handling empty response
  • Loading branch information
cindreta authored Dec 15, 2024
2 parents a889649 + eac169d commit 6194a99
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/Factories/DataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ public function make(Request $request, JsonResponse|Response|SymfonyResponse $re

$errors = [];

try {
$responseBody = $this->masker->mask(
(array) json_decode(
(string) $response->getContent(),
true,
512,
JSON_THROW_ON_ERROR
),
);
} catch (Throwable) {
$responseBody = '{}';
$responseContent = (string) $response->getContent();
$responseBody = '{}';

if (!empty($responseContent)) {
$decodedJson = json_decode($responseContent, true, 512);
if (json_last_error() === JSON_ERROR_NONE) {
try {
$responseBody = $this->masker->mask((array) $decodedJson);
} catch (Throwable) {
// Handle masking error by falling back to '{}'
}
}
}

if (! empty($response->exception)) {
Expand Down

0 comments on commit 6194a99

Please sign in to comment.