-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathAPIException.java
More file actions
86 lines (71 loc) · 2.55 KB
/
APIException.java
File metadata and controls
86 lines (71 loc) · 2.55 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.chargebee;
import org.json.*;
import java.util.List;
import java.util.Map;
public class APIException extends RuntimeException {
public final JSONObject jsonObj;
public final int httpStatusCode;
public final String type;
public final String param;
public final String apiErrorCode;
public final String errorCauseId;
public final Map<String, List<String>> headers;
/**
* Use {@link #httpStatusCode} instead.
* @deprecated
*/
@Deprecated
public final int httpCode;
/**
* Use {@link #apiErrorCode} instead.
* @deprecated
*/
@Deprecated
public final String code;
private final String message;
public APIException(int httpStatusCode, String message, JSONObject jsonObj) {
super(message);
this.jsonObj = jsonObj;
this.httpStatusCode = httpStatusCode;
try {
this.apiErrorCode = jsonObj.getString("api_error_code");
this.code = jsonObj.getString("error_code");
this.message = jsonObj.getString("error_msg");
} catch (JSONException ex) {
throw new RuntimeException("Error when parsing the error response. Probably not ChargeBee' error response.", ex);
}
this.headers = null;
this.type = jsonObj.optString("type");
this.param = jsonObj.optString("param");
this.errorCauseId = jsonObj.optString("error_cause_id");
this.httpCode = httpStatusCode;
}
public APIException(int httpStatusCode, String message, JSONObject jsonObj, Map<String, List<String>> headers) {
super(message);
this.jsonObj = jsonObj;
this.httpStatusCode = httpStatusCode;
try {
this.apiErrorCode = jsonObj.getString("api_error_code");
this.code = jsonObj.getString("error_code");
this.message = jsonObj.getString("error_msg");
} catch (JSONException ex) {
throw new RuntimeException("Error when parsing the error response. Probably not ChargeBee' error response.", ex);
}
this.headers = headers;
this.type = jsonObj.optString("type");
this.param = jsonObj.optString("param");
this.errorCauseId = jsonObj.optString("error_cause_id");
this.httpCode = httpStatusCode;
}
public boolean isParamErr() {
return param != null;
}
@Override
public String toString() {
try {
return jsonObj.toString(2);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
}