Skip to main content

ApiError

Enum ApiError 

Source
pub enum ApiError {
    NotFound(String),
    Conflict(String),
    BadRequest(String),
    Forbidden(String),
    TooManyRequests {
        message: String,
        retry_after_secs: u64,
    },
    GlobalCapacity {
        message: String,
        retry_after_secs: u64,
    },
    Unauthorized(String),
    Internal(Error),
}
Expand description

Every way a request can fail, already carrying the HTTP status it maps to – handlers return Result<_, ApiError> and let ? do the conversion (see the From impls below), the same “one error enum, converted at the boundary” shape bhtune-cli’s commands use with anyhow::Result.

Variants§

§

NotFound(String)

The requested resource doesn’t exist (a template name, a run id). 404.

§

Conflict(String)

The request conflicts with existing state (a name collision on create, a delete blocked by a foreign-key reference). 409.

§

BadRequest(String)

The request body/query itself is malformed or fails domain validation (DcsTemplate::validate, an unparseable filter value axum’s extractors didn’t already reject). 400.

§

Forbidden(String)

The request was authenticated but is not permitted. 403.

§

TooManyRequests

A per-client or per-session limit was exceeded. 429, with a Retry-After header.

Fields

§message: String
§retry_after_secs: u64
§

GlobalCapacity

The public demo has exhausted a global capacity limit. 503, with a Retry-After header. Keeping this distinct from per-client throttling lets callers avoid telling a client that its own request rate caused shared service saturation.

Fields

§message: String
§retry_after_secs: u64
§

Unauthorized(String)

No valid demo identity was supplied. 401.

§

Internal(Error)

Anything else: a database connection/query failure, or any other unexpected error. Deliberately doesn’t echo the underlying error’s Display text into the response body (logged via tracing::error! instead) – an internal error’s detail is for the server’s own logs, not a client that can’t act on it. 500.

Trait Implementations§

Source§

impl Debug for ApiError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<DbError> for ApiError

Source§

fn from(err: DbError) -> Self

bhtune_db::DbError::TemplateInUse is the one variant a client can actually act on (stop trying to delete a template still referenced by a saved loop) – everything else is an infrastructure-level failure the client can’t distinguish or fix, so it collapses to ApiError::Internal.

Source§

impl From<Error> for ApiError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for ApiError

Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more