postRequest method leads to 500 Type error

Created on 3 December 2024, 16 days ago

Problem/Motivation

The website encountered an unexpected error. Try again later.

TypeError: json_decode(): Argument #1 ($json) must be of type string, GuzzleHttp\Psr7\Response given in json_decode() (line 26 of core/lib/Drupal/Component/Serialization/Json.php).
Drupal\Component\Serialization\Json::decode() (Line: 130)
Drupal\zoomapi\Plugin\ApiTools\Client->postRequest() (Line: 253)
Drupal\apitools\Api\Client\ClientBase->request() (Line: 295)
Drupal\apitools\Api\Client\ClientBase->post() (Line: 393)

Steps to reproduce

Just make the ZOOM API request fail by maybe entering wrong keys.

Proposed resolution

diff --git a/src/Plugin/ApiTools/Client.php b/src/Plugin/ApiTools/Client.php
index 78d9b8d..3e4517f 100644
--- a/src/Plugin/ApiTools/Client.php
+++ b/src/Plugin/ApiTools/Client.php
@@ -127,7 +127,7 @@ class Client extends ClientBase {
    * {@inheritdoc}
    */
   protected function postRequest($response) {
-    return Json::decode($response);
+    return is_string($response) ? Json::decode($response) : $response;
   }

   /**
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇮🇳India u_tiwari

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024