]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix exception handling while trying different API versions
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 18 Apr 2021 20:07:35 +0000 (23:07 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 18 Apr 2021 20:07:35 +0000 (23:07 +0300)
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/err/HTTPException.java

index 8b795ac1296ab703a74918a3a53393ba7418882f..8ac793663eb686ccc00d428db93b965ef8c4a2f8 100644 (file)
@@ -407,8 +407,7 @@ public class RetrieveTransactionsTask extends
             return retrieveAccountListForVersion(apiVersion);
         }
     }
-    private List<LedgerAccount> retrieveAccountListAnyVersion()
-            throws HTTPException, ApiNotSupportedException {
+    private List<LedgerAccount> retrieveAccountListAnyVersion() throws ApiNotSupportedException {
         for (API ver : API.allVersions) {
             try {
                 return retrieveAccountListForVersion(ver);
@@ -419,10 +418,9 @@ public class RetrieveTransactionsTask extends
                                 ver.getDescription()));
             }
 
-            throw new ApiNotSupportedException();
         }
 
-        throw new RuntimeException("This should never be reached");
+        throw new ApiNotSupportedException();
     }
     private List<LedgerAccount> retrieveAccountListForVersion(API version)
             throws IOException, HTTPException {
@@ -483,16 +481,15 @@ public class RetrieveTransactionsTask extends
             try {
                 return retrieveTransactionListForVersion(ver);
             }
-            catch (Exception | HTTPException e) {
+            catch (Exception e) {
                 Logger.debug("json",
                         String.format(Locale.US, "Error during account list retrieval using API %s",
                                 ver.getDescription()));
             }
 
-            throw new ApiNotSupportedException();
         }
 
-        throw new RuntimeException("This should never be reached");
+        throw new ApiNotSupportedException();
     }
     private List<LedgerTransaction> retrieveTransactionListForVersion(API apiVersion)
             throws IOException, ParseException, HTTPException {
@@ -590,8 +587,8 @@ public class RetrieveTransactionsTask extends
         }
         catch (HTTPException e) {
             e.printStackTrace();
-            return new Result(String.format("HTTP error %d: %s", e.getResponseCode(),
-                    e.getResponseMessage()));
+            return new Result(
+                    String.format("HTTP error %d: %s", e.getResponseCode(), e.getMessage()));
         }
         catch (IOException e) {
             e.printStackTrace();
index 17b578c4987ef644435e47413591b36d792daf1e..7d281650caa41f8d7f57817c1f2dc3c1a74783e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2021 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
 
 package net.ktnx.mobileledger.err;
 
-public class HTTPException extends Throwable {
+public class HTTPException extends Exception {
     private final int responseCode;
-    private final String responseMessage;
     public int getResponseCode() {
         return responseCode;
     }
-    public String getResponseMessage() {
-        return responseMessage;
-    }
     public HTTPException(int responseCode, String responseMessage) {
+        super(responseMessage);
         this.responseCode = responseCode;
-        this.responseMessage = responseMessage;
     }
 }