{
if(t.getClass().equals(NotFound.class))
return Mono.error(t);
+ if(!(t instanceof WebClientResponseException))
+ return
+ Mono.error(
+ WebClientResponseException.create(
+ 500,
+ "Internal Server Error - Cause: " + t.getMessage(),
+ null,
+ null,
+ null));
return
Mono.error(
import static org.mockito.Mockito.when;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClientResponseException;
+import org.springframework.web.reactive.function.client.WebClientResponseException.InternalServerError;
import org.springframework.web.reactive.function.client.WebClientResponseException.NotFound;
import org.springframework.web.reactive.function.client.WebClientResponseException.ServiceUnavailable;
import reactor.core.publisher.Mono;
.verify();
}
+ @Test
+ @DisplayName("Internal error while fetching data from remote-server")
+ void testOtherErrors()
+ {
+ Mono<String> mono = Mono.error(new RuntimeException("Boom!"));
+ when(service.getRemoteText("foo")).thenReturn(mono);
+
+ Mono<String> result = controller.fetch("foo");
+
+ StepVerifier
+ .create(result)
+ .expectErrorSatisfies((t) ->
+ {
+ assertThat(t).isInstanceOf(InternalServerError.class);
+ assertThat(t.getMessage()).isEqualTo("500 Internal Server Error - Cause: Boom!");
+ })
+ .verify();
+ }
+
WebClientResponseException exception(int status)
{