-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStreamApiException.java
More file actions
105 lines (93 loc) · 2.64 KB
/
Copy pathStreamApiException.java
File metadata and controls
105 lines (93 loc) · 2.64 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
package io.getstream.exceptions;
import java.util.Collections;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
/**
* Thrown when the Stream API returns a 4xx/5xx response. Carries the parsed {@code APIError}
* envelope.
*
* <p>Checked subclass of {@link StreamException}: existing {@code throws StreamException}
* declarations continue to compile.
*/
public class StreamApiException extends StreamException {
private static final long serialVersionUID = 1L;
private final int statusCode;
private final int code;
private final Map<String, String> exceptionFields;
private final boolean unrecoverable;
private final String rawResponseBody;
@Nullable private final String moreInfo;
@Nullable private final Object details;
public StreamApiException(
String message,
int statusCode,
int code,
@Nullable Map<String, String> exceptionFields,
boolean unrecoverable,
String rawResponseBody,
@Nullable String moreInfo,
@Nullable Object details,
@Nullable Throwable cause) {
super(
message,
cause,
buildResponseData(
statusCode,
code,
message,
exceptionFields,
unrecoverable,
rawResponseBody,
moreInfo,
details));
this.statusCode = statusCode;
this.code = code;
this.exceptionFields = exceptionFields != null ? exceptionFields : Collections.emptyMap();
this.unrecoverable = unrecoverable;
this.rawResponseBody = rawResponseBody != null ? rawResponseBody : "";
this.moreInfo = moreInfo;
this.details = details;
}
private static ResponseData buildResponseData(
int statusCode,
int code,
String message,
@Nullable Map<String, String> exceptionFields,
boolean unrecoverable,
String rawResponseBody,
@Nullable String moreInfo,
@Nullable Object details) {
ResponseData rd = new ResponseData();
rd.setStatusCode(statusCode);
rd.setCode(code);
rd.setMessage(message);
rd.setExceptionFields(exceptionFields);
rd.setUnrecoverable(unrecoverable);
rd.setMoreInfo(moreInfo);
rd.setDetails(details);
return rd;
}
public int getStatusCode() {
return statusCode;
}
public int getCode() {
return code;
}
public Map<String, String> getExceptionFields() {
return exceptionFields;
}
public boolean isUnrecoverable() {
return unrecoverable;
}
public String getRawResponseBody() {
return rawResponseBody;
}
@Nullable
public String getMoreInfo() {
return moreInfo;
}
@Nullable
public Object getDetails() {
return details;
}
}