grpc-errors icon indicating copy to clipboard operation
grpc-errors copied to clipboard

Java implementation

Open BulatMukhutdinov opened this issue 8 years ago • 4 comments

Hi Thank you for your nice lib! Can you please also provide an example in Java?

BulatMukhutdinov avatar Oct 19 '17 08:10 BulatMukhutdinov

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

avinassh avatar Nov 03 '17 14:11 avinassh

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

simplesteph avatar May 04 '18 11:05 simplesteph

@avinassh Hi,Can you please also provide an example in PHP?

jyiL avatar Jun 27 '18 09:06 jyiL

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());
    }
  }

mfickett avatar Oct 02 '20 18:10 mfickett