Browse Source

Return basic response object in all cases

pull/88/head
michael 11 years ago
parent
commit
cc07679afe
  1. 5
      core/src/main/java/feign/MethodHandler.java
  2. 12
      core/src/test/java/feign/FeignTest.java

5
core/src/main/java/feign/MethodHandler.java

@ -136,7 +136,6 @@ interface MethodHandler { @@ -136,7 +136,6 @@ interface MethodHandler {
if (logLevel.get() != Logger.Level.NONE) {
response = logger.logAndRebufferResponse(metadata.configKey(), logLevel.get(), response, elapsedTime);
}
if (response.status() >= 200 && response.status() < 300) {
if (Response.class == metadata.returnType()) {
if (response.body() == null) {
return response;
@ -144,7 +143,9 @@ interface MethodHandler { @@ -144,7 +143,9 @@ interface MethodHandler {
// Ensure the response body is disconnected
byte[] bodyData = Util.toByteArray(response.body().asInputStream());
return Response.create(response.status(), response.reason(), response.headers(), bodyData);
} else if (void.class == metadata.returnType()) {
}
if (response.status() >= 200 && response.status() < 300) {
if (void.class == metadata.returnType()) {
return null;
} else {
return decode(response);

12
core/src/test/java/feign/FeignTest.java

@ -536,4 +536,16 @@ public class FeignTest { @@ -536,4 +536,16 @@ public class FeignTest {
server.shutdown();
}
}
@Test
public void responseTypeGetsReturnedDirectlyEvenWithErrorResponseCode() throws Exception {
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setResponseCode(404));
server.play();
TestInterface testInterface = Feign.builder().options(new Request.Options(1000, 1000))
.target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = testInterface.response();
assertEquals(response.status(), 404);
}
}

Loading…
Cancel
Save