Skip to content

Commit

Permalink
Also wrap the exception of Decoder.decode() in case of a 404. (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfalke authored and adriancole committed Nov 8, 2016
1 parent 95f78cb commit 7b646ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/feign/SynchronousMethodHandler.java
Expand Up @@ -133,7 +133,7 @@ Object executeAndDecode(RequestTemplate template) throws Throwable {
return decode(response); return decode(response);
} }
} else if (decode404 && response.status() == 404) { } else if (decode404 && response.status() == 404) {
return decoder.decode(response, metadata.returnType()); return decode(response);
} else { } else {
throw errorDecoder.decode(metadata.configKey(), response); throw errorDecoder.decode(metadata.configKey(), response);
} }
Expand Down
6 changes: 4 additions & 2 deletions core/src/test/java/feign/FeignTest.java
Expand Up @@ -52,6 +52,7 @@


import static feign.Util.UTF_8; import static feign.Util.UTF_8;
import static feign.assertj.MockWebServerAssertions.assertThat; import static feign.assertj.MockWebServerAssertions.assertThat;
import static org.hamcrest.CoreMatchers.isA;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


Expand Down Expand Up @@ -546,9 +547,10 @@ public Object decode(Response response, Type type) throws IOException {
} }


@Test @Test
public void decoderCanThrowUnwrappedExceptionInDecode404Mode() throws Exception { public void decodingExceptionGetWrappedInDecode404Mode() throws Exception {
server.enqueue(new MockResponse().setResponseCode(404)); server.enqueue(new MockResponse().setResponseCode(404));
thrown.expect(NoSuchElementException.class); thrown.expect(DecodeException.class);
thrown.expectCause(isA(NoSuchElementException.class));;


TestInterface api = new TestInterfaceBuilder() TestInterface api = new TestInterfaceBuilder()
.decode404() .decode404()
Expand Down

0 comments on commit 7b646ab

Please sign in to comment.