Skip to content

Commit

Permalink
refactor: use json_last_error instead of guzzle's wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
MHajoha committed Sep 18, 2024
1 parent 66c6da4 commit 79bf9bd
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions classes/api/package_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
namespace qtype_questionpy\api;

use coding_exception;
use core\http_client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\InvalidArgumentException;
use GuzzleHttp\Utils;
use moodle_exception;
use Psr\Http\Message\ResponseInterface;
use qtype_questionpy\array_converter\array_converter;
Expand Down Expand Up @@ -183,9 +180,8 @@ private function guzzle_post_and_maybe_retry(string $uri, array $options = [], b
throw $e;
}

try {
$json = Utils::jsonDecode($e->getResponse()->getBody(), assoc: true);
} catch (InvalidArgumentException) {
$json = json_decode($e->getResponse()->getBody(), associative: true);
if (JSON_ERROR_NONE !== json_last_error()) {
// Not valid JSON, so the problem probably isn't a missing package file.
throw $e;
}
Expand Down

0 comments on commit 79bf9bd

Please sign in to comment.