From 24eea00d6f49faeaf5bbbdad6178dc53ecfa08a5 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 18 Apr 2021 23:07:35 +0300 Subject: [PATCH] fix exception handling while trying different API versions --- .../async/RetrieveTransactionsTask.java | 15 ++++++--------- .../net/ktnx/mobileledger/err/HTTPException.java | 10 +++------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index 8b795ac1..8ac79366 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -407,8 +407,7 @@ public class RetrieveTransactionsTask extends return retrieveAccountListForVersion(apiVersion); } } - private List retrieveAccountListAnyVersion() - throws HTTPException, ApiNotSupportedException { + private List 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 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 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(); diff --git a/app/src/main/java/net/ktnx/mobileledger/err/HTTPException.java b/app/src/main/java/net/ktnx/mobileledger/err/HTTPException.java index 17b578c4..7d281650 100644 --- a/app/src/main/java/net/ktnx/mobileledger/err/HTTPException.java +++ b/app/src/main/java/net/ktnx/mobileledger/err/HTTPException.java @@ -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 @@ -17,17 +17,13 @@ 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; } } -- 2.39.2