-
So, by defining a GRpcServerAdvice, one can customize how exceptions are being translated to proper grpc error Status ( The Is there a way to define a sort of ServerAdvice that outputs the more verbose Status object ? (And, of course to get it into the client?) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Just return Status object from your advice built with standard api https://github.com/grpc/grpc-java/blob/master/api/src/main/java/io/grpc/Status.java and you should get it in client. |
Beta Was this translation helpful? Give feedback.
-
Okay, this is what I ended up with: @GRpcExceptionHandler
public Status handle(MessageException aExc, GRpcExceptionScope aScope) {
log.error("Exception processing in method {}", aScope.getMethodDescriptor().getFullMethodName());
ErrorInfo.Builder builder = ErrorInfo.newBuilder()
.setDomain(itsDomain)
.setReason(aExc.getReason());
for (Map.Entry<String, String> entry : aExc.getExtraData().entrySet()) {
builder.putMetadata(entry.getKey(), entry.getValue());
}
com.google.rpc.Status status = com.google.rpc.Status.newBuilder()
.setCode(aExc.getStatus().getCode().value())
.setMessage(aExc.getMessage())
.addDetails(Any.pack(builder.build()))
.build();
StatusRuntimeException exception = StatusProto.toStatusRuntimeException(status);
if (exception.getTrailers() != null) {
aScope.getResponseHeaders().merge(exception.getTrailers());
}
return exception.getStatus();
} |
Beta Was this translation helpful? Give feedback.
Okay, this is what I ended up with: