Skip to content

Commit 0c511c9

Browse files
authored
Update SquareApiException.java (#150)
1 parent c9608b0 commit 0c511c9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/java/com/squareup/square/core/SquareApiException.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class SquareApiException extends SquareException {
3636
*/
3737
private final Object body;
3838

39+
private final Map<String, List<String>> headers;
40+
3941
private final List<Error> errors;
4042

4143
public SquareApiException(String message, int statusCode, Object body) {
@@ -45,6 +47,18 @@ public SquareApiException(String message, int statusCode, Object body) {
4547
this.errors = parseErrors(body);
4648
}
4749

50+
public ApiError(String message, int statusCode, Object body, Response rawResponse) {
51+
super(message);
52+
this.statusCode = statusCode;
53+
this.body = body;
54+
this.headers = new HashMap<>();
55+
rawResponse.headers().forEach(header -> {
56+
String key = header.component1();
57+
String value = header.component2();
58+
this.headers.computeIfAbsent(key, _str -> new ArrayList<>()).add(value);
59+
});
60+
}
61+
4862
/**
4963
* @return the statusCode
5064
*/
@@ -66,6 +80,13 @@ public List<Error> errors() {
6680
return this.errors;
6781
}
6882

83+
/**
84+
* @return the headers
85+
*/
86+
public Map<String, List<String>> headers() {
87+
return this.headers;
88+
}
89+
6990
@java.lang.Override
7091
public String toString() {
7192
return "SquareClientApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: "

0 commit comments

Comments
 (0)