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"); } diff --git a/lang/en/error.php b/lang/en/error.php index d80be302266..f0ba2c304ee 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -468,6 +468,7 @@ $string['notownerofkey'] = 'You are not owner of this key'; $string['nousers'] = 'No such user!'; $string['oauth1accesstoken'] = 'OAuth 1.0 error: We did not obtain the access token.'; $string['oauth1requesttoken'] = 'OAuth 1.0 error: We did not obtain the request token - the service provider may be temporarily down.'; +$string['oauth2refreshtokenerror'] = 'Could not refresh OAuth 2 token. HTTP status for remote endpoint: {$a}'; $string['onlyadmins'] = 'Only administrators can do that'; $string['onlyeditingteachers'] = 'Only editing teachers can do that'; $string['onlyeditown'] = 'You can only edit your own information';