1
0
mirror of https://github.com/beestat/app.git synced 2025-05-24 02:14:03 -04:00

Fixed #154 - Patreon tokens are not refreshing properly

I had copy/pasted this from the ecobee connection and forgot to change a few things for error handling.
This commit is contained in:
Jon Ziebell 2019-08-28 21:12:24 -04:00
parent 8f71679733
commit 82563f3a55

View File

@ -110,24 +110,36 @@ class patreon extends external_api {
$response = json_decode($curl_response, true);
if ($response === null) {
// If this hasn't already been logged, log the error.
if($this::$log_mysql !== 'all') {
$this->log_mysql($curl_response);
}
throw new Exception('Invalid JSON');
}
// "response": "{\"errors\":[{\"code\":1,\"code_name\":\"Unauthorized\",\"detail\":\"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.\",\"id\":\"f4776cc7-0965-4d24-833a-98c449c8ffc8\",\"status\":\"401\",\"title\":\"Unauthorized\"}]}"
// If the token was expired, refresh it and try again. Trying again sets
// auto_refresh_token to false to prevent accidental infinite refreshing if
// something bad happens.
if (isset($response['status']) === true && $response['status']['code'] === 14) {
if (isset($response['errors']) === true && $response['status'] === '401') {
// Authentication token has expired. Refresh your tokens.
if ($auto_refresh_token === true) {
$this->api('patreon_token', 'refresh');
return $this->patreon_api($method, $endpoint, $arguments, false);
}
else {
if($this::$log_mysql !== 'all') {
$this->log_mysql($curl_response);
}
throw new Exception($response['status']['message']);
}
}
else if (isset($response['status']) === true && $response['status']['code'] !== 0) {
else if (isset($response['errors']) === true) {
// Any other error
if($this::$log_mysql !== 'all') {
$this->log_mysql($curl_response);
}
throw new Exception($response['status']['message']);
}
else {