]> git.basschouten.com Git - openhab-addons.git/commitdiff
Catch json parsing errors when getting login token. (#13189)
authorDan Cunningham <dan@digitaldan.com>
Fri, 29 Jul 2022 17:06:48 +0000 (10:06 -0700)
committerGitHub <noreply@github.com>
Fri, 29 Jul 2022 17:06:48 +0000 (19:06 +0200)
Fixes #13181

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
bundles/org.openhab.binding.myq/src/main/java/org/openhab/binding/myq/internal/handler/MyQAccountHandler.java

index f426158917696b0f47b937540694b1b46108ad00..9f3cdd29ade33b84b5a4baf58f0c6c1e5142fcc9 100644 (file)
@@ -342,12 +342,16 @@ public class MyQAccountHandler extends BaseBridgeHandler implements AccessTokenR
             ContentResponse tokenResponse = getLoginToken(location, codeVerifier);
             String loginToken = tokenResponse.getContentAsString();
 
-            AccessTokenResponse accessTokenResponse = gsonLowerCase.fromJson(loginToken, AccessTokenResponse.class);
-            if (accessTokenResponse == null) {
-                throw new MyQAuthenticationException("Could not parse token response");
+            try {
+                AccessTokenResponse accessTokenResponse = gsonLowerCase.fromJson(loginToken, AccessTokenResponse.class);
+                if (accessTokenResponse == null) {
+                    throw new MyQAuthenticationException("Could not parse token response");
+                }
+                getOAuthService().importAccessTokenResponse(accessTokenResponse);
+                return accessTokenResponse;
+            } catch (JsonSyntaxException e) {
+                throw new MyQCommunicationException("Invalid Token Response " + loginToken);
             }
-            getOAuthService().importAccessTokenResponse(accessTokenResponse);
-            return accessTokenResponse;
         } catch (IOException | ExecutionException | TimeoutException | OAuthException | URISyntaxException e) {
             throw new MyQCommunicationException(e.getMessage());
         }