-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShipEngineException.java
More file actions
227 lines (199 loc) · 5.69 KB
/
ShipEngineException.java
File metadata and controls
227 lines (199 loc) · 5.69 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package com.shipengine.exception;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
/**
* An error thrown by the ShipEngine SDK. All other SDK errors inherit from this
* class.
*/
public class ShipEngineException extends RuntimeException {
public static HashSet<String> getEnums() {
HashSet<String> values = new HashSet<>();
for (ErrorSource k : ErrorSource.values()) {
values.add(k.name());
}
for (ErrorType p : ErrorType.values()) {
values.add(p.name());
}
for (ErrorCode c : ErrorCode.values()) {
values.add(c.name());
}
return values;
}
public enum ErrorSource {
CARRIER,
ORDER_SOURCE,
SHIPENGINE
}
public enum ErrorType {
ACCOUNT_STATUS,
AUTHORIZATION,
BUSINESS_RULES,
ERROR,
SECURITY,
SYSTEM,
VALIDATION,
WALLET,
FUNDING_SOURCES
}
public enum ErrorCode {
ADDRESS_NOT_FOUND,
AUTO_FUND_NOT_SUPPORTED,
BATCH_CANNOT_BE_MODIFIED,
CARRIER_CONFLICT,
CARRIER_NOT_CONNECTED,
CARRIER_NOT_SUPPORTED,
CONFIRMATION_NOT_SUPPORTED,
FIELD_CONFLICT,
FIELD_VALUE_REQUIRED,
FORBIDDEN,
IDENTIFIER_CONFLICT,
IDENTIFIER_MUST_MATCH,
INCOMPATIBLE_PAIRED_LABELS,
INVALID_ADDRESS,
INVALID_BILLING_PLAN,
INVALID_CHARGE_EVENT,
INVALID_FIELD_VALUE,
INVALID_IDENTIFIER,
INVALID_STATUS,
INVALID_STRING_LENGTH,
LABEL_IMAGES_NOT_SUPPORTED,
METER_FAILURE,
MINIMUM_POSTAL_CODE_VERIFICATION_FAILED,
NOT_FOUND,
PARTIALLY_VERIFIED_TO_PREMISE_LEVEL,
RATE_LIMIT_EXCEEDED,
REQUEST_BODY_REQUIRED,
RETURN_LABEL_NOT_SUPPORTED,
SUBSCRIPTION_INACTIVE,
TERMS_NOT_ACCEPTED,
TIMEOUT,
TRACKING_NOT_SUPPORTED,
TRIAL_EXPIRED,
UNAUTHORIZED,
UNSPECIFIED,
VERIFICATION_CONFLICT,
WAREHOUSE_CONFLICT,
WEBHOOK_EVENT_TYPE_CONFLICT,
FUNDING_SOURCE_MISSING_CONFIGURATION,
FUNDING_SOURCE_ERROR
}
/**
* If the error came from the ShipEngine server (as opposed to a client-side
* error) then this is the unique ID of the HTTP request that returned the
* error. You can use this ID when contacting ShipEngine support for help.
*/
private String requestID;
/**
* Indicates where the error originated. This lets you know whether you should
* contact ShipEngine for support or if you should contact the carrier or
* marketplace instead.
*
* @see <a href=
* "https://www.shipengine.com/docs/errors/codes/#error-source">...</a>
*/
private ErrorSource source;
/**
* Indicates the type of error that occurred, such as a validation error, a
* security error, etc.
*
* @see <a href=
* "https://www.shipengine.com/docs/errors/codes/#error-type">...</a>
*/
private ErrorType type;
/**
* A code that indicates the specific error that occurred, such as missing a
* required field, an invalid address, a timeout, etc.
*
* @see <a href=
* "https://www.shipengine.com/docs/errors/codes/#error-code">...</a>
*/
private ErrorCode code;
/**
* Some errors include a URL that you can visit to learn more about the error,
* find out how to resolve it, or get support.
*/
private URL url;
public String getRequestID() {
return requestID;
}
public ErrorSource getSource() {
return source;
}
public ErrorType getType() {
return type;
}
public ErrorCode getCode() {
return code;
}
public URL getUrl() {
return url;
}
public void setRequestID(String requestID) {
this.requestID = requestID;
}
public void setSource(ErrorSource source) {
this.source = source;
}
public void setType(ErrorType type) {
this.type = type;
}
public void setCode(ErrorCode code) {
this.code = code;
}
public void setUrl(String url) {
try {
this.url = new URL(url);
} catch (MalformedURLException err) {
err.printStackTrace();
}
}
public ShipEngineException(
String message,
String requestID,
ErrorSource source,
ErrorType type,
ErrorCode code,
String url) {
super(message);
setRequestID(requestID);
setSource(source);
setType(type);
setCode(code);
setUrl(url);
}
public ShipEngineException(
String message,
ErrorSource source,
ErrorType type,
ErrorCode code,
String url) {
super(message);
setSource(source);
setType(type);
setCode(code);
setUrl(url);
}
public ShipEngineException(
String message,
String requestID,
String source,
String type,
String code) {
super(message);
setRequestID(requestID);
setSource(ErrorSource.valueOf(source.toUpperCase()));
setType(ErrorType.valueOf(type.toUpperCase()));
setCode(ErrorCode.valueOf(code.toUpperCase()));
}
public ShipEngineException(
String message,
String source,
String type,
String code) {
super(message);
setSource(ErrorSource.valueOf(source.toUpperCase()));
setType(ErrorType.valueOf(type.toUpperCase()));
setCode(ErrorCode.valueOf(code.toUpperCase()));
}
}