From 79bf9bd75e1d4bbaadbf4d0f88cf06c112dd4928 Mon Sep 17 00:00:00 2001 From: Maximilian Haye Date: Tue, 3 Sep 2024 15:59:16 +0200 Subject: [PATCH] refactor: use json_last_error instead of guzzle's wrapper --- classes/api/package_api.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/classes/api/package_api.php b/classes/api/package_api.php index ed19271f..c5309953 100644 --- a/classes/api/package_api.php +++ b/classes/api/package_api.php @@ -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; @@ -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; }