From 5f0c0f272616f59e57d46b6e52fdd24345c6fcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20T=C3=B3th=20Tam=C3=A1s?= <41370836+jtotht@users.noreply.github.com> Date: Thu, 13 Jul 2023 18:54:38 +0200 Subject: [PATCH] Fix server fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server fallback is activated only if `downloadFeed` returns `null`, which previously happened only if an exception was thrown. This happens e.g. if the server is totally offline and thus the connection times out, but it doesn’t happen if the server is online but doesn’t work (which is the case right now: https://de1.api.radio-browser.info/ is online, but reports 503 Service Unavailable). Change `Utils.downloadFeed()` to log an error and return `null` if there is an HTTP response, but it’s unsuccessful (i.e. the status code is not in the 2xx range). Returning `null` triggers the fallback mechanism. --- app/src/main/java/net/programmierecke/radiodroid2/Utils.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/net/programmierecke/radiodroid2/Utils.java b/app/src/main/java/net/programmierecke/radiodroid2/Utils.java index ce984b5ba..67c547c19 100644 --- a/app/src/main/java/net/programmierecke/radiodroid2/Utils.java +++ b/app/src/main/java/net/programmierecke/radiodroid2/Utils.java @@ -179,6 +179,11 @@ private static String downloadFeed(OkHttpClient httpClient, Context ctx, String String responseStr = response.body().string(); + if (!response.isSuccessful()) { + Log.e("UTIL", "Unsuccessful response: " + response.message() + "\n" + responseStr); + return null; + } + writeFileCache(ctx, theURI, responseStr); if (BuildConfig.DEBUG) { Log.d("UTIL", "wrote cache file for:" + theURI);