|
50 | 50 | import feign.querymap.FieldQueryMapEncoder; |
51 | 51 | import java.io.IOException; |
52 | 52 | import java.lang.reflect.Type; |
| 53 | +import java.net.ProtocolException; |
53 | 54 | import java.net.URI; |
54 | 55 | import java.time.Clock; |
55 | 56 | import java.time.Instant; |
@@ -708,6 +709,39 @@ void throwsRetryableExceptionIfNoUnderlyingCause() throws Exception { |
708 | 709 | assertThat(exception.getMessage()).contains(message); |
709 | 710 | } |
710 | 711 |
|
| 712 | + @Test |
| 713 | + void doesNotUnwrapUndeclaredCheckedCauseWhenPropagationPolicyIsUnwrap() { |
| 714 | + TestInterface api = |
| 715 | + Feign.builder() |
| 716 | + .exceptionPropagationPolicy(UNWRAP) |
| 717 | + .retryer(new DefaultRetryer(1, 1, 1)) |
| 718 | + .client( |
| 719 | + (_, _) -> { |
| 720 | + throw new ProtocolException("missing Location header for redirect"); |
| 721 | + }) |
| 722 | + .target(TestInterface.class, "http://localhost:" + server.getPort()); |
| 723 | + |
| 724 | + RetryableException exception = assertThrows(RetryableException.class, () -> api.post()); |
| 725 | + assertThat(exception.getMessage()).contains("missing Location header for redirect"); |
| 726 | + } |
| 727 | + |
| 728 | + @Test |
| 729 | + void unwrapDeclaredCheckedCauseWhenPropagationPolicyIsUnwrap() { |
| 730 | + TestInterface api = |
| 731 | + Feign.builder() |
| 732 | + .exceptionPropagationPolicy(UNWRAP) |
| 733 | + .retryer(new DefaultRetryer(1, 1, 1)) |
| 734 | + .client( |
| 735 | + (_, _) -> { |
| 736 | + throw new ProtocolException("missing Location header for redirect"); |
| 737 | + }) |
| 738 | + .target(TestInterface.class, "http://localhost:" + server.getPort()); |
| 739 | + |
| 740 | + ProtocolException exception = |
| 741 | + assertThrows(ProtocolException.class, () -> api.postThrowsProtocolException()); |
| 742 | + assertThat(exception.getMessage()).contains("missing Location header for redirect"); |
| 743 | + } |
| 744 | + |
711 | 745 | @Test |
712 | 746 | void whenReturnTypeIsResponseNoErrorHandling() { |
713 | 747 | Map<String, Collection<String>> headers = new LinkedHashMap<>(); |
@@ -1234,6 +1268,9 @@ interface TestInterface { |
1234 | 1268 | @RequestLine("POST /") |
1235 | 1269 | String post() throws TestInterfaceException; |
1236 | 1270 |
|
| 1271 | + @RequestLine("POST /") |
| 1272 | + String postThrowsProtocolException() throws ProtocolException; |
| 1273 | + |
1237 | 1274 | @RequestLine("POST /") |
1238 | 1275 | @Body( |
1239 | 1276 | "%7B\"customer_name\": \"{customer_name}\", \"user_name\": \"{user_name}\", \"password\":" |
|
0 commit comments