Add ResponseCodeException

This commit is contained in:
seven332 committed 2015-01-27 20:10:46 +08:00
1 parent b1f952d722
commit 6ae4fa1506
1 file changed
+59
@@ -15,5 +15,64 @@
package com.hippo.network;
import android.util.SparseArray;
public class ResponseCodeException extends Exception {
private static final SparseArray<String> ERROR_MESSAGE_ARRAY;
private static final String DEFAULT_ERROR_MESSAGE = "Error response code";
private final int mResponseCode;
private final String mMessage;
static {
ERROR_MESSAGE_ARRAY = new SparseArray<>(24);
ERROR_MESSAGE_ARRAY.append(400, "Bad Request");
ERROR_MESSAGE_ARRAY.append(401, "Unauthorized");
ERROR_MESSAGE_ARRAY.append(402, "Payment Required");
ERROR_MESSAGE_ARRAY.append(403, "Forbidden");
ERROR_MESSAGE_ARRAY.append(404, "Not Found");
ERROR_MESSAGE_ARRAY.append(405, "Method Not Allowed");
ERROR_MESSAGE_ARRAY.append(406, "Not Acceptable");
ERROR_MESSAGE_ARRAY.append(407, "Proxy Authentication Required");
ERROR_MESSAGE_ARRAY.append(408, "Request Timeout");
ERROR_MESSAGE_ARRAY.append(409, "Conflict");
ERROR_MESSAGE_ARRAY.append(410, "Gone");
ERROR_MESSAGE_ARRAY.append(411, "Length Required");
ERROR_MESSAGE_ARRAY.append(412, "Precondition Failed");
ERROR_MESSAGE_ARRAY.append(413, "Request Entity Too Large");
ERROR_MESSAGE_ARRAY.append(414, "Request-URI Too Long");
ERROR_MESSAGE_ARRAY.append(415, "Unsupported Media Type");
ERROR_MESSAGE_ARRAY.append(416, "Requested Range Not Satisfiable");
ERROR_MESSAGE_ARRAY.append(417, "Expectation Failed");
ERROR_MESSAGE_ARRAY.append(500, "Internal Server Error");
ERROR_MESSAGE_ARRAY.append(501, "Not Implemented");
ERROR_MESSAGE_ARRAY.append(502, "Bad Gateway");
ERROR_MESSAGE_ARRAY.append(503, "Service Unavailable");
ERROR_MESSAGE_ARRAY.append(504, "Gateway Timeout");
ERROR_MESSAGE_ARRAY.append(505, "HTTP Version Not Supported");
}
public ResponseCodeException(int responseCode) {
mResponseCode = responseCode;
mMessage = ERROR_MESSAGE_ARRAY.get(responseCode, DEFAULT_ERROR_MESSAGE);
}
public ResponseCodeException(int responseCode, String message) {
mResponseCode = responseCode;
mMessage = message;
}
@Override
public String getMessage() {
return mMessage;
}
@Override
public String getLocalizedMessage() {
return getMessage();
}
}