-
Notifications
You must be signed in to change notification settings - Fork 572
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
Exposing GrpcResponse.grpcResponseToException #2814
Conversation
89f77ea
to
e8c35ab
Compare
try { | ||
grpcStatusDetailsBin = Base64.getDecoder().decode(it) | ||
} catch (e: IllegalArgumentException) { | ||
throw IOException( |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
There was a problem hiding this 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() |
There was a problem hiding this comment.
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? { |
There was a problem hiding this comment.
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? {
}
We'll try working on interceptors instead soon. |
To help with #2769. cc @sergeys-opera