Default static implementation of "prepareErrors" in
com.salesforce.reactorgrpc.stub.ServerCalls
com.salesforce.rx3grpc.stub.ServerCalls
com.salesforce.rxgrpc.stub.ServerCalls
can't be customized. But sometimes it is very helpful:
You can define generic exception mapping on a service level in one place instead of setting it in every method.
Handle "JVM fatal" exceptions that are not propagated to onError reactive operator.
By overriding "prepareError" method, users can put some custom logic of handling in a service. For example:
new ReactorGreeterGrpc.GreeterImplBase() {
@Override
public Mono<HelloResponse> sayHello(Mono<HelloRequest> reactorRequest) {
return reactorRequest.map(this::map);
}
private HelloResponse map(HelloRequest request) {
// some critical exception can happen anywhere
throw new NoSuchMethodError("Fatal!");
}
@Override
protected Throwable onErrorMap(Throwable throwable) {
// Override can contain any logic that will be executed in case of error
if (throwable instanceof NoSuchMethodError) {
return Status.INTERNAL.withDescription("NoSuchMethod:" + throwable.getMessage()).asRuntimeException();
}
return super.onErrorMap(throwable);
}
};
Default static implementation of "prepareErrors" in
By overriding "prepareError" method, users can put some custom logic of handling in a service. For example: