10
10
import javax .ws .rs .core .MediaType ;
11
11
import javax .ws .rs .core .Response ;
12
12
import javax .ws .rs .core .Response .StatusType ;
13
+ import javax .ws .rs .core .MultivaluedMap ;
13
14
15
+ import java .util .Objects ;
14
16
import org .gitlab4j .api .utils .JacksonJson ;
15
17
16
18
import com .fasterxml .jackson .databind .JsonNode ;
@@ -26,7 +28,8 @@ public class GitLabApiException extends Exception {
26
28
private int httpStatus ;
27
29
private String message ;
28
30
private Map <String , List <String >> validationErrors ;
29
-
31
+ private MultivaluedMap <String , String > headers ;
32
+
30
33
/**
31
34
* Create a GitLabApiException instance with the specified message.
32
35
*
@@ -59,6 +62,7 @@ public GitLabApiException(Response response) {
59
62
super ();
60
63
statusInfo = response .getStatusInfo ();
61
64
httpStatus = response .getStatus ();
65
+ headers = response .getStringHeaders ();
62
66
63
67
if (response .hasEntity ()) {
64
68
@@ -87,7 +91,7 @@ public GitLabApiException(Response response) {
87
91
while (fields .hasNext ()) {
88
92
89
93
Entry <String , JsonNode > field = fields .next ();
90
- String fieldName = field .getKey ();
94
+ String fieldName = field .getKey ();
91
95
List <String > values = new ArrayList <>();
92
96
validationErrors .put (fieldName , values );
93
97
for (JsonNode value : field .getValue ()) {
@@ -186,16 +190,25 @@ public boolean hasValidationErrors() {
186
190
}
187
191
188
192
/**
189
- * Returns a Map<String, List<String>> instance containing validation errors if this GitLabApiException
193
+ * Returns a Map<String, List<String>> instance containing validation errors if this GitLabApiException
190
194
* was caused by validation errors on the GitLab server, otherwise returns null.
191
195
*
192
- * @return a Map<String, List<String>> instance containing validation errors if this GitLabApiException
196
+ * @return a Map<String, List<String>> instance containing validation errors if this GitLabApiException
193
197
* was caused by validation errors on the GitLab server, otherwise returns null
194
198
*/
195
199
public Map <String , List <String >> getValidationErrors () {
196
200
return (validationErrors );
197
201
}
198
202
203
+ /**
204
+ * Returns the response headers. Returns null if the causing error was not a response related exception.
205
+ *
206
+ * @return the response headers or null.
207
+ */
208
+ public final MultivaluedMap <String , String > getHeaders () {
209
+ return (headers );
210
+ }
211
+
199
212
@ Override
200
213
public int hashCode () {
201
214
final int prime = 31 ;
@@ -204,6 +217,7 @@ public int hashCode() {
204
217
result = prime * result + ((message == null ) ? 0 : message .hashCode ());
205
218
result = prime * result + ((statusInfo == null ) ? 0 : statusInfo .hashCode ());
206
219
result = prime * result + ((validationErrors == null ) ? 0 : validationErrors .hashCode ());
220
+ result = prime * result + ((headers == null ) ? 0 : headers .hashCode ());
207
221
return result ;
208
222
}
209
223
@@ -248,6 +262,10 @@ public boolean equals(Object obj) {
248
262
return false ;
249
263
}
250
264
265
+ if (!Objects .equals (this .headers , other .headers )) {
266
+ return false ;
267
+ }
268
+
251
269
return true ;
252
270
}
253
271
}
0 commit comments