Reputation: 349
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?
Upvotes: 0
Views: 1195
Reputation: 9937
You can use onErrorResume
operator which lets you define a fallback in case of errors.
Upvotes: 1