Handle exception for WebClientRequestException

This commit is contained in:
woo-jin.shin 2021-09-06 22:36:12 +09:00
parent 98c34bb468
commit b7fe17ab2c
1 changed files with 12 additions and 7 deletions

View File

@ -4,22 +4,23 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
@Slf4j
@Component
public class ProcessorAPIWebClient {
@Value("${webclient.base-url}")
private String baseUrl;
private final WebClient webClient;
public ProcessorAPIWebClient(WebClient.Builder webClientBuilder) {
this.webClient = webClientBuilder.baseUrl("http://localhost:20081")
public ProcessorAPIWebClient(WebClient.Builder webClientBuilder,
@Value("${webclient.base-url}") String baseUrl) {
this.webClient = webClientBuilder.baseUrl(baseUrl)
.build();
}
@ -27,6 +28,10 @@ public class ProcessorAPIWebClient {
return webClient.post()
.uri("/api/v1/crawl/boards/{boardName}", boardName)
.exchangeToMono(e -> e.bodyToMono(new ParameterizedTypeReference<String>() {}))
.publishOn(Schedulers.boundedElastic());
.publishOn(Schedulers.boundedElastic())
.onErrorResume(WebClientRequestException.class, t -> {
log.info("Exception occured, ignoring. : {}", t.getClass().getSimpleName());
return Mono.empty();
});
}
}