2

I am using Armeria 1.3.0 and protobuf for a gRPC service. I've tried to use rich error model when handling exceptions but I think Armeria seems to only support standard error model.

How can I use rich error model in Armeria? I want to return custom error code/message and more details about error when exception occurred.

Thanks for your answer in advance.

trustin
  • 12,231
  • 6
  • 42
  • 52
chacha
  • 23
  • 3
  • Hi! What is a rich model? – trustin Jan 22 '21 at 09:21
  • Looks like this one: https://grpc.io/docs/guides/error/#richer-error-model – trustin Jan 22 '21 at 09:40
  • That's right. There's some example using google protobuf according to this link https://stackoverflow.com/questions/48748745/pattern-for-rich-error-handling-in-grpc – chacha Jan 25 '21 at 00:32
  • Yeah, did you try to specify such information in `Metadata`? I think it should be doable with Armeria. – trustin Jan 25 '21 at 03:54
  • I tried to use Metadata but it is only possible when used with responseObserver.onError method not exceptionMapping of GrpcService.Builder. The exceptionMapping method only returns Status, so I tricky tried like this, `return Status.INTERNAL.asRuntimeException(metadata).getStatus()` but metadata.get method returns null in the grpc client. – chacha Jan 25 '21 at 09:05
  • I looked into GrpcServiceBuilder related codes of armeria. I think these are the reason that the metadata doesn't have any. `doClose(GrpcStatus.fromThrowable(statusFunction, exception), metadata);` of `close(Throwable exception, Metadata metadata)` method in the ArmeriaServerCall class – chacha Jan 26 '21 at 06:25
  • I have created a new issue for this question: https://github.com/line/armeria/issues/3307 However, do you think the workaround mentioned in the issue page will work for your case? If so, let me add a proper answer to this question. – trustin Jan 26 '21 at 14:17
  • I think your mention in the issue page would work for me if the exceptionMapping method is also included in the update item list. Thanks. – chacha Jan 27 '21 at 00:56
  • I see. Let me add an answer that explains the current state of this issue. – trustin Jan 28 '21 at 01:02

1 Answers1

1

It was not possible to attach arbitrary gRPC Metadata to a gRPC error response till Armeria 1.5.0, but you will be able to do so from the next minor update (1.6.0):

GrpcService
    .builder()
    .addExceptionMapping(MyException.class, (cause, metadata) -> {
        metadata.put(MY_KEY, myValue)
        return Status.XXX.withDescription("...");
    })
    ...

See https://github.com/line/armeria/pull/3329 for the detail.

trustin
  • 12,231
  • 6
  • 42
  • 52