Trait tonic_error::TonicError
source · [−]pub trait TonicError<'de>: Serialize + Deserialize<'de> + Display {
fn to_status(&self) -> Status { ... }
fn from_status(s: &'de Status) -> Result<Self, TonicErrorError> { ... }
}Expand description
A trait to convert a custom error type into a tonic::Status and back
again. The custom error is serialized to json using serde_json and stored
in the Status metadata.
The tonic::Code::Internal is used when converting to the Status, and
required when converting from a Status. A
TonicErrorError::InvalidStatusCode will be returned if the Status is any
other code. A TonicErrorError::ErrorKeyNotFound will be returned if the
data is not present in the Status metadata map.
Provided Methods
Convert this type into a tonic::Status by serializing it into the
metadata map. If serde_json fails, or if the String does not parse
into a MetadataValue<Ascii> then this will be reported in the Status
itself as an internal error.
fn from_status(s: &'de Status) -> Result<Self, TonicErrorError>
fn from_status(s: &'de Status) -> Result<Self, TonicErrorError>
Deserialize this type out of a tonic::Status metadata field. Errors
will be returned if the Status is not Code::Internal or if there is
no data present in the metadata map that we can deserialize.