Skip to content

Commit

Permalink
Fix server fallback (#1161)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jtotht authored Sep 27, 2023
1 parent 625dc3c commit 7468713
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/net/programmierecke/radiodroid2/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7468713

Please sign in to comment.