/
AGErrorInfo.java
60 lines (48 loc) · 1.21 KB
/
AGErrorInfo.java
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
package com.franz.agraph.http;
public class AGErrorInfo {
private AGErrorType errorType;
private String errMSg;
public AGErrorInfo(String errMsg) {
assert errMsg != null : "errMsg must not be null";
this.errMSg = errMsg;
}
public AGErrorInfo(AGErrorType errorType, String errMsg) {
this(errMsg);
this.errorType = errorType;
}
public AGErrorType getErrorType() {
return errorType;
}
public String getErrorMessage() {
return errMSg;
}
@Override
public String toString() {
if (errorType != null) {
StringBuilder sb = new StringBuilder(64);
sb.append(errorType);
sb.append(": ");
sb.append(errMSg);
return sb.toString();
}
else {
return errMSg;
}
}
/**
* Parses the string output that is produced by {@link #toString()}.
*/
public static AGErrorInfo parse(String errInfoString) {
String message = errInfoString;
AGErrorType errorType = null;
int colonIdx = errInfoString.indexOf(':');
if (colonIdx >= 0) {
String label = errInfoString.substring(0, colonIdx).trim();
errorType = AGErrorType.forLabel(label);
if (errorType != null) {
message = errInfoString.substring(colonIdx + 1);
}
}
return new AGErrorInfo(errorType, message.trim());
}
}