From 30272777adadaf43796a41fdf63978fd18255c77 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 1 Apr 2019 10:40:56 +0200 Subject: [PATCH] Handle GitHib errors --- .../main/java/eu/faircode/email/ActivityView.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 67546b0598..1a19293ec7 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -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,7 +815,10 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB @Override protected void onException(Bundle args, Throwable ex) { if (args.getBoolean("always")) - Helper.unexpectedError(ActivityView.this, ActivityView.this, ex); + 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"); }