MDL-70282 oauth: Improve error information

If the request to the OAuth 2 token endpoint fails show the response
body the endpoint returned with its HTTP status (when debug: DEVELOPER).
If no response is available show any error returned by Curl.  Previously
none of this information was available making troubleshooting difficult.

If a token refresh fails in \core\oauth2\refresh_system_tokens_task an
exception is now thrown so that the result is shown as "Fail" on
admin/tasklogs.php?filter=core\oauth2\refresh_system_tokens_task
This commit is contained in:
Leon Stringer
2021-01-28 10:02:58 +00:00
parent 500bee1af0
commit 6a6cd2bb5d
4 changed files with 14 additions and 2 deletions
+2 -1
View File
@@ -403,7 +403,8 @@ class client extends \oauth2_client {
}
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);