Handle GitHib errors

This commit is contained in:
M66B 2019-04-01 10:40:56 +02:00
parent 5d681e56aa
commit 30272777ad
1 changed files with 11 additions and 1 deletions

View File

@ -744,6 +744,13 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
while ((line = br.readLine()) != null)
response.append(line);
if (status == HttpsURLConnection.HTTP_FORBIDDEN) {
// {"message":"API rate limit exceeded for ...","documentation_url":"https://developer.github.com/v3/#rate-limiting"}
JSONObject jmessage = new JSONObject(response.toString());
if (jmessage.has("message"))
throw new IllegalArgumentException(jmessage.getString("message"));
throw new IOException("HTTP " + status + ": " + response.toString());
}
if (status != HttpsURLConnection.HTTP_OK)
throw new IOException("HTTP " + status + ": " + response.toString());
@ -808,6 +815,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override
protected void onException(Bundle args, Throwable ex) {
if (args.getBoolean("always"))
if (ex instanceof IllegalArgumentException)
Snackbar.make(getVisibleView(), ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(ActivityView.this, ActivityView.this, ex);
}
}.execute(this, args, "update:check");