pub struct TwirpError { /* private fields */ }
Expand description
A Twirp error
It is composed of three elements:
- An error
code
that is member of a fixed listTwirpErrorCode
- A human error
message
describing the error as a string - A set of “
meta
” key-value pairs as strings holding arbitrary metadata describing the error.
let error = TwirpError::not_found("Object foo not found").with_meta("id", "foo");
assert_eq!(error.code(), TwirpErrorCode::NotFound);
assert_eq!(error.message(), "Object foo not found");
assert_eq!(error.meta("id"), Some("foo"));
Implementations§
Source§impl TwirpError
impl TwirpError
pub fn code(&self) -> TwirpErrorCode
pub fn message(&self) -> &str
pub fn into_message(self) -> String
pub fn new(code: TwirpErrorCode, msg: impl Into<String>) -> Self
pub fn wrap( code: TwirpErrorCode, msg: impl Into<String>, e: impl Error + Send + Sync + 'static, ) -> Self
Sourcepub fn with_meta(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn with_meta(self, key: impl Into<String>, value: impl Into<String>) -> Self
Set an associated metadata
pub fn aborted(msg: impl Into<String>) -> Self
pub fn already_exists(msg: impl Into<String>) -> Self
pub fn canceled(msg: impl Into<String>) -> Self
pub fn dataloss(msg: impl Into<String>) -> Self
pub fn invalid_argument(msg: impl Into<String>) -> Self
pub fn internal(msg: impl Into<String>) -> Self
pub fn deadline_exceeded(msg: impl Into<String>) -> Self
pub fn failed_precondition(msg: impl Into<String>) -> Self
pub fn malformed(msg: impl Into<String>) -> Self
pub fn not_found(msg: impl Into<String>) -> Self
pub fn out_of_range(msg: impl Into<String>) -> Self
pub fn permission_denied(msg: impl Into<String>) -> Self
pub fn required_argument(msg: impl Into<String>) -> Self
pub fn resource_exhausted(msg: impl Into<String>) -> Self
pub fn unauthenticated(msg: impl Into<String>) -> Self
pub fn unimplemented(msg: impl Into<String>) -> Self
Trait Implementations§
Source§impl Clone for TwirpError
impl Clone for TwirpError
Source§fn clone(&self) -> TwirpError
fn clone(&self) -> TwirpError
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for TwirpError
impl Debug for TwirpError
Source§impl<'de> Deserialize<'de> for TwirpError
impl<'de> Deserialize<'de> for TwirpError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for TwirpError
impl Display for TwirpError
Source§impl Error for TwirpError
impl Error for TwirpError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<Status> for TwirpError
Available on crate feature tonic-014
only.
impl From<Status> for TwirpError
Available on crate feature
tonic-014
only.Source§fn from(status: Status) -> TwirpError
fn from(status: Status) -> TwirpError
Converts to this type from the input type.
Source§impl<B: From<String>> From<TwirpError> for Response<B>
Available on crate feature http
only.
impl<B: From<String>> From<TwirpError> for Response<B>
Available on crate feature
http
only.Source§fn from(error: TwirpError) -> Self
fn from(error: TwirpError) -> Self
Converts to this type from the input type.
Source§impl From<TwirpError> for Status
Available on crate feature tonic-014
only.
impl From<TwirpError> for Status
Available on crate feature
tonic-014
only.Source§fn from(error: TwirpError) -> Self
fn from(error: TwirpError) -> Self
Converts to this type from the input type.
Source§impl IntoResponse for TwirpError
Available on crate feature axum-08
only.
impl IntoResponse for TwirpError
Available on crate feature
axum-08
only.Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.
Source§impl PartialEq for TwirpError
impl PartialEq for TwirpError
Source§impl Serialize for TwirpError
impl Serialize for TwirpError
impl Eq for TwirpError
Auto Trait Implementations§
impl Freeze for TwirpError
impl !RefUnwindSafe for TwirpError
impl Send for TwirpError
impl Sync for TwirpError
impl Unpin for TwirpError
impl !UnwindSafe for TwirpError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request