From fe3f0a01209a8b3d2fefce1bc89629758202ee99 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 12 Nov 2023 21:04:33 +0100 Subject: [PATCH] Revert "VirusTotal: : use HttpStatusException" This reverts commit 64b05a6641f87c446b547b90d64ffbc6d0239db3. --- .../java/eu/faircode/email/VirusTotal.java | 19 ++++++++----------- .../email/FragmentDialogVirusTotal.java | 3 +-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/src/extra/java/eu/faircode/email/VirusTotal.java b/app/src/extra/java/eu/faircode/email/VirusTotal.java index a8f788cc8e..71df98c2be 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,8 +62,7 @@ public class VirusTotal { static Bundle lookup(Context context, File file, String apiKey) throws NoSuchAlgorithmException, IOException, JSONException { Bundle result = new Bundle(); - String u = "api/v3/files/"; - Pair response = call(context, u + getHash(file), apiKey); + Pair response = call(context, "api/v3/files/" + getHash(file), apiKey); if (response.first == HttpsURLConnection.HTTP_OK) { // https://developers.virustotal.com/reference/files // Example: https://gist.github.com/M66B/4ea95fdb93fb10bf4047761fcc9ec21a @@ -89,17 +88,16 @@ public class VirusTotal { result.putString("label", label); } } else if (response.first != HttpsURLConnection.HTTP_NOT_FOUND) - throw new HttpStatusException(response.second, response.first, u); + throw new FileNotFoundException(response.second); return result; } static String upload(Context context, File file, String apiKey) throws IOException, JSONException { // Get upload URL - String u = "api/v3/files/upload_url"; - Pair response = call(context, u, apiKey); + Pair response = call(context, "api/v3/files/upload_url", apiKey); if (response.first != HttpsURLConnection.HTTP_OK) - throw new HttpStatusException(response.second, response.first, u); + throw new FileNotFoundException(response.second); JSONObject jurl = new JSONObject(response.second); String upload_url = jurl.getString("data"); @@ -157,7 +155,7 @@ public class VirusTotal { Log.w(ex); } Log.w("VT " + error); - throw new HttpStatusException(error, status, url.toString()); + throw new FileNotFoundException(error); } String r = Helper.readStream(connection.getInputStream()); @@ -174,10 +172,9 @@ 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++) { - String u = "api/v3/analyses/"; - Pair analyses = call(context, u + id, apiKey); + Pair analyses = call(context, "api/v3/analyses/" + id, apiKey); if (analyses.first != HttpsURLConnection.HTTP_OK) - throw new HttpStatusException(analyses.second, analyses.first, u); + throw new FileNotFoundException(analyses.second); 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 cf93b9b499..44409a4efe 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogVirusTotal.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogVirusTotal.java @@ -38,7 +38,6 @@ 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; @@ -191,7 +190,7 @@ public class FragmentDialogVirusTotal extends FragmentDialogBase { @Override protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(getParentFragmentManager(), ex, !(ex instanceof IOException)); + Log.unexpectedError(getParentFragmentManager(), ex); } };