当前位置: 代码迷 >> 综合 >> WebFlux系列(十)WebClient 异常处理
  详细解决方案

WebFlux系列(十)WebClient 异常处理

热度:20   发布时间:2024-01-25 01:57:21.0

#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分钟视频学习