July 2018
Intermediate to advanced
268 pages
7h 36m
English
A WebClient instance allows you to handle errors (the WebClientTestImpl class) in the listMovies() method, as follows:
@Overridepublic Flux<Movie> listMovies() { return webClient.get().uri("/") .retrieve() .onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.error(new SampleException()) ) .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new SampleException()) ) .bodyToFlux(Movie.class);}
SampleException is a custom exception class that we created by extending the Exception class. We are handling 4xx and 5xx errors, and, when encountered, it sends the custom exception as response.
Read now
Unlock full access