Commit Graph
3 Commits
Author SHA1 Message Date
Tom DyasandGitHub ff6a690cec fix(build): Correctly convert Empty to () (#734) 2021-10-22 08:44:27 -04:00
Tom DyasandGitHub b90bb7bbc0 feat(tonic): add h2::Error as a source for Status (#612)
## Motivation

A gRPC server may send a HTTP/2 GOAWAY frame with NO_ERROR status to gracefully shutdown a connection. This appears to Tonic users as a `tonic::Status` with `Code::Internal` and the message set to `h2 protocol error: protocol error: not a result of an error`.

The only way to currently detect this case and differentiate it from other internal errors (e.g., an application-level internal error) is to match on the message. A client may want to differentiate these cases because it may only want to alert on the application-level internal error and not on the transient transport-level issue. (Indeed, this is the use case for which I'm envisioning using this change.)

Matching on a message is not as robust, however, as matching on an `h2::Error` and its reason code. (The message could change for example if a future version of Tonic decided to vary the message. This would break any users that matched on the previous version of the message.)

## Solution

Store the `h2::Error` used when creating a `tonic::Status` from a `h2::Error` and provide it as the `source` for purposes of `std::error::Error`. This will allow users to downcast it and match on the original `h2::Reason`.
2021-06-23 08:34:07 +02:00
Tom DyasandGitHub 0d05aa0d02 feat: Expose status constructors (#579) 2021-04-07 17:39:05 -04:00