我有一个问题
如何在状态5xx上返回空助焊剂?
@Override
public Flux<Repository> getAllUserRepositories(User user) {
return WebClient.create()
.get()
.uri(hostname + ":" + port + "/user" + "/repos" + "?access_token=" + ACCESS_TOKEN + "&type=private")
.retrieve()
.onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new WebServerException("Problem with service", null)))
.bodyToFlux(Repository.class)
.filter(repository -> repository.getName().contains(user.getName()));
}
答案 0 :(得分:1)
您可以如下使用onErrorResume
:
return WebClient.create()
.get()
.uri(hostname + ":" + port + "/user" + "/repos" + "?access_token=" + ACCESS_TOKEN + "&type=private")
.retrieve()
.onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new WebServerException("Problem with service", null)))
.bodyToFlux(Repository.class)
.onErrorResume(WebServerException.class, (e) -> Flux.empty())
.filter(repository -> repository.getName().contains(user.getName()));