pub struct ServiceError {
pub status: RpcStatus,
pub code: u32,
pub message: String,
}Expand description
Error type that maps to RPC response errors
Services can either use this directly or define their own error types
that implement Into<ServiceError>.
Fields§
§status: RpcStatusRPC status category
code: u32Error code (maps to RpcStatus or custom service codes)
message: StringHuman-readable error message
Implementations§
Source§impl ServiceError
impl ServiceError
Sourcepub fn new(status: RpcStatus, code: u32, message: impl Into<String>) -> Self
pub fn new(status: RpcStatus, code: u32, message: impl Into<String>) -> Self
Create a new service error
Sourcepub fn invalid_request(message: impl Into<String>) -> Self
pub fn invalid_request(message: impl Into<String>) -> Self
Invalid request (bad input, validation failed) - code 400
Unauthorized (authentication required) - code 401
Sourcepub fn forbidden(message: impl Into<String>) -> Self
pub fn forbidden(message: impl Into<String>) -> Self
Forbidden (authenticated but not allowed) - code 403
Sourcepub fn internal(message: impl Into<String>) -> Self
pub fn internal(message: impl Into<String>) -> Self
Internal error (something went wrong) - code 500
Service unavailable - code 503
Sourcepub fn custom(code: u32, message: impl Into<String>) -> Self
pub fn custom(code: u32, message: impl Into<String>) -> Self
Custom service-specific error
Use codes starting from your service’s allocated range. See CLAUDE.md for error code ranges:
- 1000-1999: Gateway errors
- 2000-2999: Auth errors
- 3000-3999: User service errors
- 4000-4999: Payment service errors
Trait Implementations§
Source§impl Clone for ServiceError
impl Clone for ServiceError
Source§fn clone(&self) -> ServiceError
fn clone(&self) -> ServiceError
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 ServiceError
impl Debug for ServiceError
Source§impl Display for ServiceError
impl Display for ServiceError
Source§impl Error for ServiceError
impl Error for ServiceError
1.30.0 · 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<Error> for ServiceError
impl From<Error> for ServiceError
Source§impl From<Error> for ServiceError
impl From<Error> for ServiceError
Source§impl From<Error> for ServiceError
impl From<Error> for ServiceError
Source§impl IntoServiceError for ServiceError
impl IntoServiceError for ServiceError
Source§fn into_service_error(self) -> ServiceError
fn into_service_error(self) -> ServiceError
Convert to ServiceError
Auto Trait Implementations§
impl Freeze for ServiceError
impl RefUnwindSafe for ServiceError
impl Send for ServiceError
impl Sync for ServiceError
impl Unpin for ServiceError
impl UnsafeUnpin for ServiceError
impl UnwindSafe for ServiceError
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.