Skip to content

Commit c8ccbaa

Browse files
committed
validate() now properly handles expected HTTP status in the 200-204 range (#203).
1 parent 6834512 commit c8ccbaa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/org/gitlab4j/api/AbstractApi.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,15 @@ protected void addFormParam(Form formData, String name, Object value, boolean re
429429
*/
430430
protected Response validate(Response response, Response.Status expected) throws GitLabApiException {
431431

432-
if (response.getStatus() != expected.getStatusCode()) {
433-
throw new GitLabApiException(response);
432+
int responseCode = response.getStatus();
433+
int expectedResponseCode = expected.getStatusCode();
434+
435+
if (responseCode != expectedResponseCode) {
436+
437+
// If the expected code is 200-204 and the response code is 200-204 it is OK. We do this because
438+
// GitLab is constantly changing the expected code in the 200 to 204 range
439+
if (expectedResponseCode > 204 || responseCode > 204 || expectedResponseCode < 200 || responseCode < 200)
440+
throw new GitLabApiException(response);
434441
}
435442

436443
if (!getApiClient().validateSecretToken(response)) {

0 commit comments

Comments
 (0)