#Java#Spring#WebFlux#Reactor#WebClient#异常处理#
WebClient 异常处理
视频讲解: https://www.bilibili.com/video/av83495354/
代码:
@GetMapping(value = "employees", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Employee> findAll() {return WebClient.create("localhost:8080/employees").get().retrieve().onStatus(HttpStatus::is5xxServerError, clientResponse -> {return Mono.error(new Cum5xxException(clientResponse.statusCode().value() + " error code"));}).onStatus(HttpStatus::is4xxClientError, clientResponse -> {return Mono.error(new Cum4xxException(clientResponse.statusCode().value() + " error code"));}).onStatus(HttpStatus::isError, clientResponse -> {return Mono.error(new Cum4xxException(clientResponse.statusCode().value() + " error code"));}).bodyToFlux(Employee.class);
}
公众号,坚持每天3分钟视频学习