question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow overriding the default gRPC status to HTTP status rules for an unframed gRPC response

See original GitHub issue

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

How can I map StatusRuntimeException to http status codes?

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
jupinycommented, Nov 21, 2021

Ah, sorry for the misunderstanding the meaning of UnstableApi; I checked a description about UnstableApi.

/**
 * 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 🙇

1reaction
ikhooncommented, Nov 21, 2021

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 UnframedGrpcStatusFunction set via GrpcServiceBuilder could be used in UnframedGrpcErrorHandler with a breaking change. As UnframedGrpcErrorHandler is an unstable API, we can add UnframedGrpcStatusFunction as the 4th parameter. https://github.com/line/armeria/blob/ef93d4cbe1657c339875b1dbc970b2f8ef848087/grpc/src/main/java/com/linecorp/armeria/server/grpc/UnframedGrpcErrorHandler.java#L111

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customizing your gateway | gRPC-Gateway - GitHub Pages
To have the most control over the HTTP response status codes, you can use custom metadata. While handling the rpc, set the intended...
Read more >
HTTP to gRPC Status Code Mapping
This table is to be used only for clients that received a response that did not include grpc-status. If grpc-status was provided, it...
Read more >
Job failed - consul connect - Nomad - HashiCorp Discuss
Parameters in the main config file override values in the default file. Do not remove "config.default" parameter from this file unless you ...
Read more >
Browsing and invoking services with DocService
of(new MyThriftHelloService())); // Add a gRPC service which implements 'GrpcHelloService'. // Unlike Thrift, you must enable unframed requests explicitly. sb.
Read more >
Emulator release notes - Android Developers
Updated foldable AVD design and default settings; Updated Wear emulator buttons; gRPC audio streaming improvements; Resizable emulator ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found