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>) -> TwirpError
pub fn wrap( code: TwirpErrorCode, msg: impl Into<String>, e: impl Error + Send + Sync + 'static, ) -> TwirpError
Sourcepub fn with_meta(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> TwirpError
pub fn with_meta( self, key: impl Into<String>, value: impl Into<String>, ) -> TwirpError
Set an associated metadata
pub fn aborted(msg: impl Into<String>) -> TwirpError
pub fn already_exists(msg: impl Into<String>) -> TwirpError
pub fn canceled(msg: impl Into<String>) -> TwirpError
pub fn dataloss(msg: impl Into<String>) -> TwirpError
pub fn invalid_argument(msg: impl Into<String>) -> TwirpError
pub fn internal(msg: impl Into<String>) -> TwirpError
pub fn deadline_exceeded(msg: impl Into<String>) -> TwirpError
pub fn failed_precondition(msg: impl Into<String>) -> TwirpError
pub fn malformed(msg: impl Into<String>) -> TwirpError
pub fn not_found(msg: impl Into<String>) -> TwirpError
pub fn out_of_range(msg: impl Into<String>) -> TwirpError
pub fn permission_denied(msg: impl Into<String>) -> TwirpError
pub fn required_argument(msg: impl Into<String>) -> TwirpError
pub fn resource_exhausted(msg: impl Into<String>) -> TwirpError
pub fn unauthenticated(msg: impl Into<String>) -> TwirpError
pub fn unimplemented(msg: impl Into<String>) -> TwirpError
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<TwirpError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TwirpError, <__D as Deserializer<'de>>::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<B> From<Response<B>> for TwirpError
impl<B> From<Response<B>> for TwirpError
Source§fn from(response: Response<B>) -> TwirpError
fn from(response: Response<B>) -> TwirpError
Converts to this type from the input type.
Source§impl From<Status> for TwirpError
impl From<Status> for TwirpError
Source§fn from(status: Status) -> TwirpError
fn from(status: Status) -> TwirpError
Converts to this type from the input type.
Source§impl IntoResponse for TwirpError
impl IntoResponse for TwirpError
Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
Create a response.
Source§impl PartialEq for TwirpError
impl PartialEq for TwirpError
Source§impl Serialize for TwirpError
impl Serialize for TwirpError
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
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, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Call the handler with the given request.
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
Apply a
tower::Layer
to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Convert the handler into a
Service
by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Convert the handler into a
Service
and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
Convert the handler into a
MakeService
and no state. Read moreSource§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