doOnError 和 onErrorResume 如何组合成一个运算符

doOnError and onErrorResume how to combine into one operator

我有 RestController,其中 return 是 Mono。如果我抓到 TimeoutException,我需要登录它并 return 我的自定义 ErrorResponse。现在,它看起来像这样:

return service.someMethod(phone, ctx)
                .doOnNext(resp -> log("done")
                .timeout(timeout)
                .doOnError(TimeoutException.class, e -> log.error(ServiceErrors.CLIENT_SEARCH_TIMEOUT_ERROR + e.getLocalizedMessage()))
                .onErrorResume(TimeoutException.class, e -> Mono.just(new MyCustomWrapper<>(
                        new MyCustomError("EIPbXsxiuA" , ServiceErrors.CLIENT_SEARCH_TIMEOUT_ERROR))
                );

我想结合使用 doOnError 和 onErrorResume。我该怎么做?

如何删除 doOnError 并将日志记录放入 onErrorResume 中,如下所示:

return service.someMethod(phone, ctx)
                .doOnNext(resp -> log("done")
                .timeout(timeout)
                .onErrorResume(TimeoutException.class, e -> {
  log.error(ServiceErrors.CLIENT_SEARCH_TIMEOUT_ERROR + e.getLocalizedMessage())
  Mono.just(new MyCustomWrapper<>(
                        new MyCustomError("EIPbXsxiuA" , ServiceErrors.CLIENT_SEARCH_TIMEOUT_ERROR))
});