diff --git a/app/src/extra/java/eu/faircode/email/VirusTotal.java b/app/src/extra/java/eu/faircode/email/VirusTotal.java index 71df98c2be..a8f788cc8e 100644 --- a/app/src/extra/java/eu/faircode/email/VirusTotal.java +++ b/app/src/extra/java/eu/faircode/email/VirusTotal.java @@ -30,10 +30,10 @@ import androidx.annotation.NonNull; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.jsoup.HttpStatusException; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -62,7 +62,8 @@ public class VirusTotal { static Bundle lookup(Context context, File file, String apiKey) throws NoSuchAlgorithmException, IOException, JSONException { Bundle result = new Bundle(); - Pair response = call(context, "api/v3/files/" + getHash(file), apiKey); + String u = "api/v3/files/"; + Pair response = call(context, u + getHash(file), apiKey); if (response.first == HttpsURLConnection.HTTP_OK) { // https://developers.virustotal.com/reference/files // Example: https://gist.github.com/M66B/4ea95fdb93fb10bf4047761fcc9ec21a @@ -88,16 +89,17 @@ public class VirusTotal { result.putString("label", label); } } else if (response.first != HttpsURLConnection.HTTP_NOT_FOUND) - throw new FileNotFoundException(response.second); + throw new HttpStatusException(response.second, response.first, u); return result; } static String upload(Context context, File file, String apiKey) throws IOException, JSONException { // Get upload URL - Pair response = call(context, "api/v3/files/upload_url", apiKey); + String u = "api/v3/files/upload_url"; + Pair response = call(context, u, apiKey); if (response.first != HttpsURLConnection.HTTP_OK) - throw new FileNotFoundException(response.second); + throw new HttpStatusException(response.second, response.first, u); JSONObject jurl = new JSONObject(response.second); String upload_url = jurl.getString("data"); @@ -155,7 +157,7 @@ public class VirusTotal { Log.w(ex); } Log.w("VT " + error); - throw new FileNotFoundException(error); + throw new HttpStatusException(error, status, url.toString()); } String r = Helper.readStream(connection.getInputStream()); @@ -172,9 +174,10 @@ public class VirusTotal { static void waitForAnalysis(Context context, String id, String apiKey) throws IOException, JSONException, InterruptedException, TimeoutException { // Get analysis result for (int i = 0; i < VT_ANALYSIS_CHECKS; i++) { - Pair analyses = call(context, "api/v3/analyses/" + id, apiKey); + String u = "api/v3/analyses/"; + Pair analyses = call(context, u + id, apiKey); if (analyses.first != HttpsURLConnection.HTTP_OK) - throw new FileNotFoundException(analyses.second); + throw new HttpStatusException(analyses.second, analyses.first, u); JSONObject janalysis = new JSONObject(analyses.second); JSONObject jdata = janalysis.getJSONObject("data"); diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogVirusTotal.java b/app/src/main/java/eu/faircode/email/FragmentDialogVirusTotal.java index 44409a4efe..cf93b9b499 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogVirusTotal.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogVirusTotal.java @@ -38,6 +38,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import java.io.File; +import java.io.IOException; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; @@ -190,7 +191,7 @@ public class FragmentDialogVirusTotal extends FragmentDialogBase { @Override protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(getParentFragmentManager(), ex); + Log.unexpectedError(getParentFragmentManager(), ex, !(ex instanceof IOException)); } };