-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow overriding the default gRPC status to HTTP status rules for an unframed gRPC response #3683
Comments
We can introduce an interface to let users override the mapping from gRPC status to HTTP status for unframed gRPC requests. interface UnframedGrpcStatusFunction {
// The default mapping.
static of() {
return (ctx, status, cause) -> GrpcStatus.grpcStatusToHttpStatus(status);
}
// If null is returned, fallback to the default mapping.
// 'cause' could be captured from `RequestLog.responseCause()`
@Nullable
HttpStatus apply(ServiceRequestContext ctx, Status status, @Nullable Throwable cause);
default UnframedGrpcStatusFunction orElse(UnframedGrpcStatusFunction other) {
return (ctx, status, cause) -> {
// apply 'other' if the current status function returns null.
};
}
}
GrpcService.builder()
.unframedGrpcStatusMapping(unframedGrpcStatusFunction); The armeria/grpc/src/main/java/com/linecorp/armeria/server/grpc/UnframedGrpcErrorHandler.java Line 111 in ef93d4c
|
Thanks for the detailed guide. Let me take this issue 😄 |
One question, could you explain about this part? 😭 |
Yes, it is. Currently, the status mapping is hard-coded. armeria/grpc/src/main/java/com/linecorp/armeria/server/grpc/UnframedGrpcErrorHandler.java Line 92 in ef93d4c
We need to pass UnframedGrpcStatusFunction to UnframedGrpcErrorHandler so that UnframedGrpcErrorHandler uses UnframedGrpcStatusFunction when building HttpResponse .
public interface UnframedGrpcErrorHandler {
- HttpResponse handle(ServiceRequestContext ctx, Status status, AggregatedHttpResponse response);
+ HttpResponse handle(ServiceRequestContext ctx, Status status, AggregatedHttpResponse response, UnframedGrpcStatusFunction statusFunction); |
Ah, sorry for the misunderstanding the meaning of /**
* Indicates the API of the target is not mature enough to guarantee the compatibility between releases.
* Its behavior, signature or even existence might change without a prior notice at any point.
*/ So you said I could add the breaking change simply. Thank you for answer 🙇 |
…vice (#3948) Motivation: - #3683 Modifications: - Introduce a `UnframedGrpcStatusMappingFunction ` - Add a `UnframedGrpcStatusMappingFunction ` parameter in `UnframedGrpcErrorHandler#of` Result: - Closes #3683 - Users can map a gRPC status to an HTTP status that they want through `UnframedGrpcErrorHandler.of(UnframedGrpcStatusMappingFunction unframedGrpcStatusMappingFunction)`.
An unframed gRPC service statically maps gRPC status to HTTP status based on https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto.
I got a question from Armera slack channel. https://line-armeria.slack.com/archives/C1NGPBUH2/p1625735446194500
Unfortunately, the answer is no. We don't provide a way to customize the default mapping rules at the moment.
It would be nice to take a custom mapping function using
GrpcServiceBuilder
.The text was updated successfully, but these errors were encountered: