-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRequestError.java
More file actions
39 lines (31 loc) · 1.01 KB
/
RequestError.java
File metadata and controls
39 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.toopher;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import java.io.IOException;
/**
* Request errors from API calls
*
*/
public class RequestError extends ClientProtocolException {
public RequestError(String message) {
super(message);
}
public RequestError(String message, Exception e) {
super(message, e);
}
public RequestError(Exception e) {
super(getSpecificExceptionMessage(e.getClass()), e);
}
private static String getSpecificExceptionMessage(Class c) {
if (ClientProtocolException.class.isAssignableFrom(c)) {
return "Http protocol error";
} else if (IOException.class.isAssignableFrom(c)) {
return "Connection error";
} else if (JSONException.class.isAssignableFrom(c)) {
return "Unexpected response format";
} else {
return "Request error";
}
}
private static final long serialVersionUID = -1479647692976296897L;
}