From f58c70ebd53743b2ce266bcf63a6fd059253f8aa Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Wed, 14 Apr 2021 10:52:34 +0200 Subject: [PATCH] MDL-71119 core_badges: Add more information to errors Some errors raised when calling external services were ignored. Displaying this information helps to debug and find the real reasons why some action, like connecting to an external backpack, can't be done. --- badges/classes/oauth2/client.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/badges/classes/oauth2/client.php b/badges/classes/oauth2/client.php index e7bc270e481..8e635bcec03 100644 --- a/badges/classes/oauth2/client.php +++ b/badges/classes/oauth2/client.php @@ -245,11 +245,13 @@ class client extends \core\oauth2\client { } // Requests can either use http GET or POST. $response = $this->post($this->token_url(), $this->build_post_data($params)); - $r = json_decode($response); if ($this->info['http_code'] !== 200) { - throw new moodle_exception('Could not upgrade oauth token'); + $debuginfo = !empty($this->error) ? $this->error : $response; + throw new moodle_exception('oauth2refreshtokenerror', 'core_error', '', $this->info['http_code'], $debuginfo); } + $r = json_decode($response); + if (is_null($r)) { throw new moodle_exception("Could not decode JSON token response"); }