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.

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

mercurial