forked from intercom/intercom-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntercomException.java
More file actions
48 lines (38 loc) · 1.48 KB
/
Copy pathIntercomException.java
File metadata and controls
48 lines (38 loc) · 1.48 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
package io.intercom.api;
public class IntercomException extends RuntimeException {
private static final long serialVersionUID = -2723350106062183796L;
private ErrorCollection errorCollection;
@SuppressWarnings("WeakerAccess")
public IntercomException(String message) {
super(message);
}
public IntercomException(String message, Throwable cause) {
super(message, cause);
}
public IntercomException(ErrorCollection errorCollection) {
this(getMessage(errorCollection));
this.errorCollection = errorCollection;
}
public static String getMessage(ErrorCollection errorCollection) {
String message = "Could not read error message from server";
if(errorCollection!=null
&& errorCollection.getErrors() != null
&& errorCollection.getErrors().size() > 0
&& errorCollection.getErrors().get(0) != null
&& errorCollection.getErrors().get(0).getMessage() != null){
message = errorCollection.getErrors().get(0).getMessage();
}
return message;
}
@SuppressWarnings("WeakerAccess")
public IntercomException(ErrorCollection errorCollection, Throwable cause) {
this(getMessage(errorCollection), cause);
this.errorCollection = errorCollection;
}
public ErrorCollection getErrorCollection() {
return errorCollection;
}
public Error getFirstError() {
return errorCollection.getErrors().get(0);
}
}