Skip to content
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

Exposing GrpcResponse.grpcResponseToException #2814

Closed

Conversation

oldergod
Copy link
Member

To help with #2769. cc @sergeys-opera

@oldergod oldergod force-pushed the bquenaudon.2024-01-31.openinggrpcResponseToException branch from 89f77ea to e8c35ab Compare January 31, 2024 11:43
try {
grpcStatusDetailsBin = Base64.getDecoder().decode(it)
} catch (e: IllegalArgumentException) {
throw IOException(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it a bit weird that transportException is returned but this IllegarArgumentException is rethrown?
IMO it would be better to only return GrpcException from this method and throw anything else.

var trailers = headersOf()
var transportException = suppressed
try {
trailers = trailers()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is guaranteed to throw if the response hasn't been consumed yet. It would be good to document this behavior or ensure it doesn't happen by buffering the response body here via response.peekBody()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Copy link
Collaborator

@swankjesse swankjesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who would call this?

var trailers = headersOf()
var transportException = suppressed
try {
trailers = trailers()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

import okio.IOException

/** Returns an exception if the gRPC call didn't have a grpc-status of 0. */
fun GrpcResponse.grpcResponseToException(suppressed: IOException? = null): IOException? {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think I like the signature of this function as a public API.

It’s job is to produce an exception if the response itself is malformed or bad.

Maybe this?

fun GrpcResponse.toExceptionIfFailed(suppressed: IOException? = null): IOException? {
}

@oldergod
Copy link
Member Author

oldergod commented Feb 7, 2024

We'll try working on interceptors instead soon.

@oldergod oldergod closed this Feb 7, 2024
@oldergod oldergod deleted the bquenaudon.2024-01-31.openinggrpcResponseToException branch February 7, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants