Skip to content

Commit

Permalink
Check for valid JSON error response (fixes #577).
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Sep 27, 2023
1 parent 9dc9454 commit 9a8f5f8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Traits/PayPalHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Exception\ClientException as HttpClientException;
use GuzzleHttp\Utils;
use Illuminate\Support\Str;
use Psr\Http\Message\StreamInterface;
use RuntimeException;

Expand Down Expand Up @@ -211,7 +212,7 @@ private function doPayPalRequest(bool $decode = true)

return ($decode === false) ? $response->getContents() : Utils::jsonDecode($response, true);
} catch (RuntimeException $t) {
$error = ($decode === false) ? $t->getMessage() : Utils::jsonDecode($t->getMessage(), true);
$error = ($decode === false) || (Str::isJson($t->getMessage()) === false) ? $t->getMessage() : Utils::jsonDecode($t->getMessage(), true);

return ['error' => $error];
}
Expand Down

0 comments on commit 9a8f5f8

Please sign in to comment.