diff --git a/library/src/org/whispersystems/textsecure/push/AuthorizationFailedException.java b/library/src/org/whispersystems/textsecure/push/AuthorizationFailedException.java new file mode 100644 index 0000000000..af3ca251fa --- /dev/null +++ b/library/src/org/whispersystems/textsecure/push/AuthorizationFailedException.java @@ -0,0 +1,9 @@ +package org.whispersystems.textsecure.push; + +import java.io.IOException; + +public class AuthorizationFailedException extends IOException { + public AuthorizationFailedException(String s) { + super(s); + } +} diff --git a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java index 104574696a..45a048d705 100644 --- a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java +++ b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java @@ -269,6 +269,10 @@ public class PushServiceSocket { throw new RateLimitException("Rate limit exceeded: " + connection.getResponseCode()); } + if (connection.getResponseCode() == 403) { + throw new AuthorizationFailedException("Authorization failed!"); + } + if (connection.getResponseCode() != 200) { throw new IOException("Bad response: " + connection.getResponseCode() + " " + connection.getResponseMessage()); } diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index efd3e310e3..93d3d5b37e 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -56,6 +56,7 @@ import org.thoughtcrime.securesms.util.MemoryCleaner; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.Trimmer; import org.thoughtcrime.securesms.util.Util; +import org.whispersystems.textsecure.push.AuthorizationFailedException; import org.whispersystems.textsecure.push.PushServiceSocket; import java.io.IOException; @@ -358,8 +359,11 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr socket.unregisterGcmId(); GCMRegistrar.unregister(context); return SUCCESS; - } catch (IOException e) { - Log.w("ApplicationPreferencesActivity", e); + } catch (AuthorizationFailedException afe) { + Log.w("ApplicationPreferencesActivity", afe); + return SUCCESS; + } catch (IOException ioe) { + Log.w("ApplicationPreferencesActivity", ioe); return NETWORK_ERROR; } }