1010import javax .ws .rs .core .MediaType ;
1111import javax .ws .rs .core .Response ;
1212import javax .ws .rs .core .Response .StatusType ;
13+ import javax .ws .rs .core .MultivaluedMap ;
1314
15+ import java .util .Objects ;
1416import org .gitlab4j .api .utils .JacksonJson ;
1517
1618import com .fasterxml .jackson .databind .JsonNode ;
@@ -26,7 +28,8 @@ public class GitLabApiException extends Exception {
2628 private int httpStatus ;
2729 private String message ;
2830 private Map <String , List <String >> validationErrors ;
29-
31+ private MultivaluedMap <String , String > headers ;
32+
3033 /**
3134 * Create a GitLabApiException instance with the specified message.
3235 *
@@ -59,6 +62,7 @@ public GitLabApiException(Response response) {
5962 super ();
6063 statusInfo = response .getStatusInfo ();
6164 httpStatus = response .getStatus ();
65+ headers = response .getStringHeaders ();
6266
6367 if (response .hasEntity ()) {
6468
@@ -87,7 +91,7 @@ public GitLabApiException(Response response) {
8791 while (fields .hasNext ()) {
8892
8993 Entry <String , JsonNode > field = fields .next ();
90- String fieldName = field .getKey ();
94+ String fieldName = field .getKey ();
9195 List <String > values = new ArrayList <>();
9296 validationErrors .put (fieldName , values );
9397 for (JsonNode value : field .getValue ()) {
@@ -186,16 +190,25 @@ public boolean hasValidationErrors() {
186190 }
187191
188192 /**
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
190194 * was caused by validation errors on the GitLab server, otherwise returns null.
191195 *
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
193197 * was caused by validation errors on the GitLab server, otherwise returns null
194198 */
195199 public Map <String , List <String >> getValidationErrors () {
196200 return (validationErrors );
197201 }
198202
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+
199212 @ Override
200213 public int hashCode () {
201214 final int prime = 31 ;
@@ -204,6 +217,7 @@ public int hashCode() {
204217 result = prime * result + ((message == null ) ? 0 : message .hashCode ());
205218 result = prime * result + ((statusInfo == null ) ? 0 : statusInfo .hashCode ());
206219 result = prime * result + ((validationErrors == null ) ? 0 : validationErrors .hashCode ());
220+ result = prime * result + ((headers == null ) ? 0 : headers .hashCode ());
207221 return result ;
208222 }
209223
@@ -248,6 +262,10 @@ public boolean equals(Object obj) {
248262 return false ;
249263 }
250264
265+ if (!Objects .equals (this .headers , other .headers )) {
266+ return false ;
267+ }
268+
251269 return true ;
252270 }
253271}
0 commit comments