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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:6c387c245ece
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/. */
4
5 package org.mozilla.gecko.sync.net;
6
7 import java.io.IOException;
8 import java.util.HashMap;
9
10 import org.mozilla.gecko.background.common.log.Logger;
11
12 import ch.boye.httpclientandroidlib.HttpResponse;
13
14 public class SyncStorageResponse extends SyncResponse {
15
16 // Responses that are actionable get constant status codes.
17 public static final String RESPONSE_CLIENT_UPGRADE_REQUIRED = "16";
18
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>();
23
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.");
42
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 }
60
61
62 public SyncStorageResponse(HttpResponse res) {
63 this.response = res;
64 }
65
66 public String getErrorMessage() throws IllegalStateException, IOException {
67 return SyncStorageResponse.getServerErrorMessage(this.body().trim());
68 }
69
70 // TODO: Content-Type and Content-Length validation.
71
72 }

mercurial