pub struct ApiError { /* private fields */ }Expand description
HTTP error type returned by every control-plane REST handler.
Wraps an HTTP status code and a JSON body (ApiErrorBody). Handlers
return Result<_, ApiError> and rely on the axum::response::IntoResponse
impl to render the response automatically.
ApiError also implements From<lightshuttle_runtime::LifecycleHandleError>,
so the ? operator converts runtime errors into the right HTTP status without
boilerplate in each handler.
Three constructors cover all current failure modes:
| Constructor | HTTP status | When to use |
|---|---|---|
ApiError::unknown_resource | 404 | Named resource does not exist |
ApiError::not_supported | 501 | Operation not implemented yet |
ApiError::runtime | 500 | Unexpected runtime failure |
Implementations§
Source§impl ApiError
impl ApiError
Sourcepub fn unknown_resource(name: impl Into<String>) -> Self
pub fn unknown_resource(name: impl Into<String>) -> Self
Build a 404 response for a resource that does not exist.
The serialised body is {"error":"unknown resource","resource":"<name>"}.
Prefer this over constructing ApiError directly so the HTTP
status and the error slug remain consistent across all handlers.
Sourcepub fn not_supported(op: &'static str) -> Self
pub fn not_supported(op: &'static str) -> Self
Build a 501 response for an operation that is not yet implemented.
The serialised body is {"error":"operation `op` is not supported yet"}.
Trait Implementations§
Source§impl From<LifecycleHandleError> for ApiError
impl From<LifecycleHandleError> for ApiError
Source§fn from(err: LifecycleHandleError) -> Self
fn from(err: LifecycleHandleError) -> Self
Source§impl IntoResponse for ApiError
impl IntoResponse for ApiError
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
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> 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>
T in a tonic::Request