Thanks for replying.
I did not quite understand the statement - "It will respond with Status.UNKNOWN and interceptors might get confused" .
Let's say I do not have the try - catch in the purge() method and I have a ServerInterceptor like below. Are you saying that the statusException.getStatus() in the below code may be Status.UNKNOWN sometime even if the validator.validate() is throwing StatusRunTImeException with some different Status. In that case statusException.getTrailers() can also be null or empty?
public class ServerInterceptor implements io.grpc.ServerInterceptor {
public < ReqT, RespT > ServerCall.Listener < ReqT > interceptCall(
final ServerCall < ReqT, RespT > call,
final Metadata requestHeaders,
final ServerCallHandler < ReqT, RespT > next) {
return new SimpleForwardingServerCallListener < > (next.startCall(grpcServerCall, requestHeaders)) {
public void onMessage(final ReqT message) {
try {
// do something
super.onMessage(message);
} catch (Exception e) {
handleException(ex);
throw ex;
}
}
// Similiar logic for onReady(), onHalfClose(), onComplete(),
// where in a try .. catch handleException() & throw ex
private void handleException(final Exception exception) {
if (exception instance of StatusRunTimeException statusException) {
val metadata = statusException.getTrailers();
log.error("Request failed with metadata={}", metadata, statusException);
call.close(statusException.getStatus(), ObjectUtils.defaultIfNull(metadata, new Metadata()));
return;
}
call.close(Status.UNKNOWN.withDescription(exception.getMessage()), requestHeaders);
}
}
}
}