pub struct ApiError {
pub kind: ErrorKind,
pub message: String,
}Expand description
One folded method’s failure.
Why: the handlers below return Result<Value, ApiError> rather than
Result<Value, RpcError> so the code mapping lives in one place instead of
at every return. That is the shape trusty-analyze’s ApiError took
through the same migration.
What: a kind and a message. The message reaches the caller verbatim.
Test: api_error_message_survives_the_conversion.
Fields§
§kind: ErrorKindWhich failure this is.
message: StringWhat to tell the caller.
Implementations§
Source§impl ApiError
impl ApiError
Sourcepub fn bad_request(msg: impl Into<String>) -> Self
pub fn bad_request(msg: impl Into<String>) -> Self
The caller’s arguments are wrong.
Sourcepub fn conflict(msg: impl Into<String>) -> Self
pub fn conflict(msg: impl Into<String>) -> Self
Understood, and refused. Formerly 409 Conflict.
Sourcepub fn forbidden(msg: impl Into<String>) -> Self
pub fn forbidden(msg: impl Into<String>) -> Self
Understood, and denied. Formerly 403 Forbidden (#1714).
Sourcepub fn unprocessable(msg: impl Into<String>) -> Self
pub fn unprocessable(msg: impl Into<String>) -> Self
Structurally valid and semantically unacceptable — content too short to be worth storing (#466). Formerly 422.
Trait Implementations§
Source§impl Error for ApiError
impl Error for ApiError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<ApiError> for RpcError
The one place a failure kind becomes a JSON-RPC code (#6286).
impl From<ApiError> for RpcError
The one place a failure kind becomes a JSON-RPC code (#6286).
Every folded method’s ? runs through here, so a change to the mapping is a
change to the whole surface rather than to whichever handler was edited last.
Test: api_error_kind_maps_to_its_rpc_code.
Source§impl From<ServiceError> for ApiError
impl From<ServiceError> for ApiError
Source§fn from(e: ServiceError) -> Self
fn from(e: ServiceError) -> Self
Auto Trait Implementations§
impl Freeze for ApiError
impl RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin for ApiError
impl UnsafeUnpin for ApiError
impl UnwindSafe for ApiError
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more