grpc-errors
grpc-errors copied to clipboard
Java implementation
Hi Thank you for your nice lib! Can you please also provide an example in Java?
Hi @BulatMukhutdinov, it might take some time with Java examples as I am not really a Java dev. However I will keep this issue open and hope someone contributes
See https://github.com/saturnism/grpc-java-by-example/tree/master/error-handling-example/error-server/src/main/java/com/example/grpc/server
Maybe you could get inspired / get a PR from the author
@avinassh Hi,Can you please also provide an example in PHP?
Thanks @simplesteph for the pointer. It looks like https://github.com/saturnism/grpc-by-example-java/blob/master/error-handling-example/error-server/src/main/java/com/example/grpc/server/ErrorServiceImpl.java#L33 is they key example:
@Override
public void customException(EchoRequest request, StreamObserver<EchoResponse> responseObserver) {
try {
throw new CustomException("Custom exception!");
} catch (Exception e) {
responseObserver.onError(Status.INTERNAL
.withDescription(e.getMessage())
.augmentDescription("customException()")
.withCause(e) // This can be attached to the Status locally, but NOT transmitted to the client!
.asRuntimeException());
}
}