0

I have some controller method like

@PostMapping("/*")
fun proxy(@RequestBody body: String): Mono<ByteArray> {
    return roundRobinBean.getNext()
        .post()
        .uri("/api")
        .body(BodyInserters.fromObject(body))
        .retrieve()
        .bodyToMono<ByteArray>()
        .doOnSuccess{
            threadPool.submit(PutToCacheJob(body, it, cacheBean))
        }
        .doOnError{
            logger.error(it.message, it)
        }
}

roundRobinBean return WebClient for some host. If i get connection timeout exception or get 500 response i need call another host or return data from cache. Have mono some handler for changing inner data?

Igor Fedorov
  • 321
  • 3
  • 17

1 Answers1

1

You can use onErrorResume operator which lets you define a fallback in case of errors.

Martin Tarjányi
  • 8,863
  • 2
  • 31
  • 49