mobile/android/base/sync/net/SyncStorageResponse.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.sync.net;
michael@0 6
michael@0 7 import java.io.IOException;
michael@0 8 import java.util.HashMap;
michael@0 9
michael@0 10 import org.mozilla.gecko.background.common.log.Logger;
michael@0 11
michael@0 12 import ch.boye.httpclientandroidlib.HttpResponse;
michael@0 13
michael@0 14 public class SyncStorageResponse extends SyncResponse {
michael@0 15
michael@0 16 // Responses that are actionable get constant status codes.
michael@0 17 public static final String RESPONSE_CLIENT_UPGRADE_REQUIRED = "16";
michael@0 18
michael@0 19 private static final String LOG_TAG = "SyncStorageResponse";
michael@0 20 public static HashMap<String, String> SERVER_ERROR_MESSAGES;
michael@0 21 static {
michael@0 22 HashMap<String, String> errors = new HashMap<String, String>();
michael@0 23
michael@0 24 // Sync protocol errors.
michael@0 25 errors.put("1", "Illegal method/protocol");
michael@0 26 errors.put("2", "Incorrect/missing CAPTCHA");
michael@0 27 errors.put("3", "Invalid/missing username");
michael@0 28 errors.put("4", "Attempt to overwrite data that can't be overwritten (such as creating a user ID that already exists)");
michael@0 29 errors.put("5", "User ID does not match account in path");
michael@0 30 errors.put("6", "JSON parse failure");
michael@0 31 errors.put("7", "Missing password field");
michael@0 32 errors.put("8", "Invalid Weave Basic Object");
michael@0 33 errors.put("9", "Requested password not strong enough");
michael@0 34 errors.put("10", "Invalid/missing password reset code");
michael@0 35 errors.put("11", "Unsupported function");
michael@0 36 errors.put("12", "No email address on file");
michael@0 37 errors.put("13", "Invalid collection");
michael@0 38 errors.put("14", "User over quota");
michael@0 39 errors.put("15", "The email does not match the username");
michael@0 40 errors.put(RESPONSE_CLIENT_UPGRADE_REQUIRED, "Client upgrade required");
michael@0 41 errors.put("255", "An unexpected server error occurred: pool is empty.");
michael@0 42
michael@0 43 // Infrastructure-generated errors.
michael@0 44 errors.put("\"server issue: getVS failed\"", "server issue: getVS failed");
michael@0 45 errors.put("\"server issue: prefix not set\"", "server issue: prefix not set");
michael@0 46 errors.put("\"server issue: host header not received from client\"", "server issue: host header not received from client");
michael@0 47 errors.put("\"server issue: database lookup failed\"", "server issue: database lookup failed");
michael@0 48 errors.put("\"server issue: database is not healthy\"", "server issue: database is not healthy");
michael@0 49 errors.put("\"server issue: database not in pool\"", "server issue: database not in pool");
michael@0 50 errors.put("\"server issue: database marked as down\"", "server issue: database marked as down");
michael@0 51 SERVER_ERROR_MESSAGES = errors;
michael@0 52 }
michael@0 53 public static String getServerErrorMessage(String body) {
michael@0 54 Logger.debug(LOG_TAG, "Looking up message for body \"" + body + "\"");
michael@0 55 if (SERVER_ERROR_MESSAGES.containsKey(body)) {
michael@0 56 return SERVER_ERROR_MESSAGES.get(body);
michael@0 57 }
michael@0 58 return body;
michael@0 59 }
michael@0 60
michael@0 61
michael@0 62 public SyncStorageResponse(HttpResponse res) {
michael@0 63 this.response = res;
michael@0 64 }
michael@0 65
michael@0 66 public String getErrorMessage() throws IllegalStateException, IOException {
michael@0 67 return SyncStorageResponse.getServerErrorMessage(this.body().trim());
michael@0 68 }
michael@0 69
michael@0 70 // TODO: Content-Type and Content-Length validation.
michael@0 71
michael@0 72 }

mercurial