Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 1xx status codes #871

Merged
merged 6 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/feign/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public final class Response implements Closeable {
private final Request request;

private Response(Builder builder) {
checkState(builder.status >= 200, "Invalid status code: %s", builder.status);
checkState(builder.status >= 100 && builder.status < 600, "Invalid status code: %s",
kdavisk6 marked this conversation as resolved.
Show resolved Hide resolved
builder.status);
checkState(builder.request != null, "original request is required");
this.status = builder.status;
this.request = builder.request;
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/feign/ResponseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import static feign.assertj.FeignAssertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.Assertions.entry;

public class ResponseTest {
Expand Down Expand Up @@ -81,4 +82,27 @@ public void headersAreOptional() {
.build();
assertThat(response.headers()).isNotNull().isEmpty();
}

@Test
public void support1xxStatusCodes() {
Response response = Response.builder()
.status(103)
.request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8))
.body((Response.Body) null)
.build();

assertThat(response.status()).isEqualTo(103);
}

@Test
public void statusCodesBeyond5xxAreNotSupported() {
Throwable thrown = catchThrowable(() -> Response.builder()
.status(600)
.request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8))
.body((Response.Body) null)
.build());

assertThat(thrown).isInstanceOf(IllegalStateException.class);
assertThat(thrown).hasMessage("Invalid status code: 600");
}
}