summaryrefslogtreecommitdiffstats
path: root/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/oauth/FxAccountAbstractClientException.java
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/oauth/FxAccountAbstractClientException.java')
-rw-r--r--mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/oauth/FxAccountAbstractClientException.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/oauth/FxAccountAbstractClientException.java b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/oauth/FxAccountAbstractClientException.java
new file mode 100644
index 000000000..21025af0a
--- /dev/null
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/oauth/FxAccountAbstractClientException.java
@@ -0,0 +1,68 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.background.fxa.oauth;
+
+import org.mozilla.gecko.sync.ExtendedJSONObject;
+import org.mozilla.gecko.sync.HTTPFailureException;
+import org.mozilla.gecko.sync.net.SyncStorageResponse;
+
+import ch.boye.httpclientandroidlib.HttpResponse;
+import ch.boye.httpclientandroidlib.HttpStatus;
+
+/**
+ * From <a href="https://github.com/mozilla/fxa-auth-server/blob/master/docs/api.md">https://github.com/mozilla/fxa-auth-server/blob/master/docs/api.md</a>.
+ */
+public class FxAccountAbstractClientException extends Exception {
+ private static final long serialVersionUID = 1953459541558266597L;
+
+ public FxAccountAbstractClientException(String detailMessage) {
+ super(detailMessage);
+ }
+
+ public FxAccountAbstractClientException(Exception e) {
+ super(e);
+ }
+
+ public static class FxAccountAbstractClientRemoteException extends FxAccountAbstractClientException {
+ private static final long serialVersionUID = 1209313149952001097L;
+
+ public final HttpResponse response;
+ public final long httpStatusCode;
+ public final long apiErrorNumber;
+ public final String error;
+ public final String message;
+ public final ExtendedJSONObject body;
+
+ public FxAccountAbstractClientRemoteException(HttpResponse response, long httpStatusCode, long apiErrorNumber, String error, String message, ExtendedJSONObject body) {
+ super(new HTTPFailureException(new SyncStorageResponse(response)));
+ if (body == null) {
+ throw new IllegalArgumentException("body must not be null");
+ }
+ this.response = response;
+ this.httpStatusCode = httpStatusCode;
+ this.apiErrorNumber = apiErrorNumber;
+ this.error = error;
+ this.message = message;
+ this.body = body;
+ }
+
+ @Override
+ public String toString() {
+ return "<FxAccountAbstractClientRemoteException " + this.httpStatusCode + " [" + this.apiErrorNumber + "]: " + this.message + ">";
+ }
+
+ public boolean isInvalidAuthentication() {
+ return this.httpStatusCode == HttpStatus.SC_UNAUTHORIZED;
+ }
+ }
+
+ public static class FxAccountAbstractClientMalformedResponseException extends FxAccountAbstractClientRemoteException {
+ private static final long serialVersionUID = 1209313149952001098L;
+
+ public FxAccountAbstractClientMalformedResponseException(HttpResponse response) {
+ super(response, 0, FxAccountOAuthRemoteError.UNKNOWN_ERROR, "Response malformed", "Response malformed", new ExtendedJSONObject());
+ }
+ }
+}