如何在Java Reactor中阻塞调用后重新抛出错误?

Vit*_*lii 2 java project-reactor

当我调用.block()Java Reactor 时,如果出现错误,它会抛出ReactiveException。我需要获取包含在其中的源异常ReactiveException并重新抛出它。

这段代码有效,但是有更好的方法来实现目标吗?

try {
    return myService.getObject(.....).block();
} catch (Exception e) {
    throw e.getCause() != null ? e.getCause() : e;
}
Run Code Online (Sandbox Code Playgroud)

Phi*_*lay 5

使用Exceptions.unwrap(e)

例如:


import reactor.core.Exceptions;

...

try {
    return myService.getObject(.....).block();
} catch (Exception e) {
    throw Exceptions.unwrap(e);
}

Run Code Online (Sandbox Code Playgroud)