From: Mark Hilbush Date: Tue, 27 Oct 2020 15:10:03 +0000 (-0400) Subject: [ecobee] Improve handling of invalid_grant error (#8857) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=a84222cf5ea8b1b74ec47d0cfe6d2060b0183667;p=openhab-addons.git [ecobee] Improve handling of invalid_grant error (#8857) Signed-off-by: Mark Hilbush --- diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/api/EcobeeApi.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/api/EcobeeApi.java index 18e1375e81..e39607c1e2 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/api/EcobeeApi.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/api/EcobeeApi.java @@ -170,13 +170,24 @@ public class EcobeeApi implements AccessTokenRefreshListener { logger.info("API: The Ecobee authorization process threw an exception", e); ecobeeAuth.setState(EcobeeAuthState.NEED_PIN); } catch (OAuthResponseException e) { - logger.info("API: Exception getting access token: error='{}', description='{}'", e.getError(), - e.getErrorDescription()); - // How to handle the possible error codes? + handleOAuthException(e); } return isAuthorized; } + private void handleOAuthException(OAuthResponseException e) { + if ("invalid_grant".equalsIgnoreCase(e.getError())) { + // Usually indicates that the refresh token is no longer valid and will require reauthorization + logger.warn("API: Received 'invalid_grant' error response. Please reauthorize application with Ecobee"); + deleteOAuthClientService(); + createOAuthClientService(); + } else { + // Other errors may not require reauthorization and/or may not apply + logger.warn("API: Exception getting access token: error='{}', description='{}'", e.getError(), + e.getErrorDescription()); + } + } + @Override public void onAccessTokenResponse(AccessTokenResponse accessTokenResponse) { }