Skip to main content

AutumnError

Struct AutumnError 

Source
pub struct AutumnError { /* private fields */ }
Expand description

Framework error type wrapping any error with an HTTP status code.

§Usage

The ? operator converts any std::error::Error into an AutumnError with status 500 Internal Server Error:

use autumn_web::prelude::*;

#[get("/")]
async fn handler() -> AutumnResult<&'static str> {
    autumn_web::reexports::tokio::fs::read_to_string("missing.txt").await?; // becomes 500 on error
    Ok("ok")
}

For expected errors, use a status refinement constructor:

use autumn_web::prelude::*;

#[get("/users/{id}")]
async fn get_user(axum::extract::Path(id): axum::extract::Path<i32>) -> AutumnResult<String> {
    if id < 0 {
        return Err(AutumnError::bad_request(
            std::io::Error::other("id must be positive"),
        ));
    }
    Ok(format!("user {id}"))
}

§Why no Error impl

AutumnError intentionally does not implement std::error::Error. Doing so would conflict with the blanket From<E: Error> impl (the reflexive From<T> for T would overlap). This type is a response wrapper, not a propagatable error.

Implementations§

Source§

impl AutumnError

Source

pub const fn with_status(self, status: StatusCode) -> Self

Override the HTTP status code.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err: AutumnError = std::io::Error::other("forbidden").into();
let err = err.with_status(StatusCode::FORBIDDEN);
assert_eq!(err.status(), StatusCode::FORBIDDEN);
Source

pub fn internal_server_error(err: impl Error + Send + Sync + 'static) -> Self

Create a 500 Internal Server Error.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::internal_server_error(std::io::Error::other("boom"));
assert_eq!(err.status(), StatusCode::INTERNAL_SERVER_ERROR);
Source

pub fn not_found(err: impl Error + Send + Sync + 'static) -> Self

Create a 404 Not Found error.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::not_found(std::io::Error::other("no such user"));
assert_eq!(err.status(), StatusCode::NOT_FOUND);
Source

pub fn bad_request(err: impl Error + Send + Sync + 'static) -> Self

Create a 400 Bad Request error.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::bad_request(std::io::Error::other("invalid input"));
assert_eq!(err.status(), StatusCode::BAD_REQUEST);
Source

pub fn unprocessable(err: impl Error + Send + Sync + 'static) -> Self

Create a 422 Unprocessable Entity error.

Use this for validation failures where the request is syntactically valid but semantically incorrect.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::unprocessable(std::io::Error::other("age must be positive"));
assert_eq!(err.status(), StatusCode::UNPROCESSABLE_ENTITY);
Source

pub fn service_unavailable(err: impl Error + Send + Sync + 'static) -> Self

Create a 503 Service Unavailable error.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::service_unavailable(std::io::Error::other("pool exhausted"));
assert_eq!(err.status(), StatusCode::SERVICE_UNAVAILABLE);
Source

pub fn unauthorized(err: impl Error + Send + Sync + 'static) -> Self

Create a 401 Unauthorized error.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::unauthorized(std::io::Error::other("not logged in"));
assert_eq!(err.status(), StatusCode::UNAUTHORIZED);
Source

pub fn forbidden(err: impl Error + Send + Sync + 'static) -> Self

Create a 403 Forbidden error.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::forbidden(std::io::Error::other("not allowed"));
assert_eq!(err.status(), StatusCode::FORBIDDEN);
Source

pub fn validation(details: HashMap<String, Vec<String>>) -> Self

Create a 422 Unprocessable Entity error with field-level validation details.

Use this when a request fails multiple field-specific validation rules (e.g., in a form submission). It attaches the details parameter, a mapping of field names to their respective error messages, so the client can display errors next to the relevant inputs.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;
use std::collections::HashMap;

let mut errors = HashMap::new();
errors.insert("username".to_string(), vec!["Username is taken".to_string()]);

let err = AutumnError::validation(errors);
assert_eq!(err.status(), StatusCode::UNPROCESSABLE_ENTITY);
Source

pub fn internal_server_error_msg(msg: impl Into<String>) -> Self

Create a 500 Internal Server Error from a plain string message.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::internal_server_error_msg("Database explosion");
assert_eq!(err.status(), StatusCode::INTERNAL_SERVER_ERROR);
Source

pub fn not_found_msg(msg: impl Into<String>) -> Self

Create a 404 Not Found error from a plain string message.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::not_found_msg("No such user");
assert_eq!(err.status(), StatusCode::NOT_FOUND);
assert_eq!(err.to_string(), "No such user");
Source

pub fn bad_request_msg(msg: impl Into<String>) -> Self

Create a 400 Bad Request error from a plain string message.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::bad_request_msg("Invalid input parameter");
assert_eq!(err.status(), StatusCode::BAD_REQUEST);
Source

pub fn unprocessable_msg(msg: impl Into<String>) -> Self

Create a 422 Unprocessable Entity error from a plain string message.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::unprocessable_msg("Title is required");
assert_eq!(err.status(), StatusCode::UNPROCESSABLE_ENTITY);
Source

pub fn unauthorized_msg(msg: impl Into<String>) -> Self

Create a 401 Unauthorized error from a plain string message.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::unauthorized_msg("Please log in to continue");
assert_eq!(err.status(), StatusCode::UNAUTHORIZED);
Source

pub fn forbidden_msg(msg: impl Into<String>) -> Self

Create a 403 Forbidden error from a plain string message.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::forbidden_msg("You lack admin privileges");
assert_eq!(err.status(), StatusCode::FORBIDDEN);
Source

pub fn service_unavailable_msg(msg: impl Into<String>) -> Self

Create a 503 Service Unavailable error from a plain string message.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::service_unavailable_msg("Database connection pool exhausted");
assert_eq!(err.status(), StatusCode::SERVICE_UNAVAILABLE);
Source

pub fn conflict(err: impl Error + Send + Sync + 'static) -> Self

Create a 409 Conflict error.

Use this for optimistic-lock conflicts surfaced by repository update calls when the client’s expected version is stale.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::conflict(std::io::Error::other("stale version"));
assert_eq!(err.status(), StatusCode::CONFLICT);
Source

pub fn conflict_msg(msg: impl Into<String>) -> Self

Create a 409 Conflict error from a plain string message.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err = AutumnError::conflict_msg("Concurrent edit: please reload and retry");
assert_eq!(err.status(), StatusCode::CONFLICT);
Source

pub const fn status(&self) -> StatusCode

Returns the HTTP status code associated with this error.

§Examples
use autumn_web::error::AutumnError;
use http::StatusCode;

let err: AutumnError = std::io::Error::other("boom").into();
assert_eq!(err.status(), StatusCode::INTERNAL_SERVER_ERROR);
Source

pub fn source_chain(&self) -> Vec<String>

Return the wrapped error’s source chain as displayable messages.

The top-level AutumnError display already prints the wrapped error message, so this list starts at that wrapped error’s first source.

Trait Implementations§

Source§

impl Debug for AutumnError

Source§

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

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

impl Display for AutumnError

Source§

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

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

impl<E> From<E> for AutumnError
where E: Error + Send + Sync + 'static,

Source§

fn from(err: E) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for AutumnError

Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HxResponseExt for T
where T: IntoResponse,

Source§

fn hx_location(self, url: &str) -> Response

Allows you to do a client-side redirect that does not do a full page reload (HX-Location).
Source§

fn hx_push_url(self, url: &str) -> Response

Pushes a new URL into the history stack (HX-Push-Url).
Source§

fn hx_redirect(self, url: &str) -> Response

Triggers a client-side redirect (HX-Redirect).
Source§

fn hx_refresh(self) -> Response

Tells the client to do a full page refresh (HX-Refresh).
Source§

fn hx_replace_url(self, url: &str) -> Response

Replaces the current URL in the location bar (HX-Replace-Url).
Source§

fn hx_reswap(self, swap: &str) -> Response

Specifies how the response will be swapped (HX-Reswap).
Source§

fn hx_retarget(self, target: &str) -> Response

Specifies the target element to update (HX-Retarget).
Source§

fn hx_trigger(self, event: &str) -> Response

Triggers client-side events (HX-Trigger).
Source§

fn hx_trigger_after_settle(self, event: &str) -> Response

Triggers client-side events after the settle step (HX-Trigger-After-Settle).
Source§

fn hx_trigger_after_swap(self, event: &str) -> Response

Triggers client-side events after the swap step (HX-Trigger-After-Swap).
Source§

impl<T> Instrument for T

Source§

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

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

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> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, Conn> RunQueryDsl<Conn> for T

Source§

fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
where Conn: AsyncConnectionCore + Send, Self: ExecuteDsl<Conn> + 'query,

Executes the given command, returning the number of rows affected. Read more
Source§

fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
where U: Send, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Executes the given query, returning a Vec with the returned rows. Read more
Source§

fn load_stream<'conn, 'query, U>( self, conn: &'conn mut Conn, ) -> Self::LoadFuture<'conn>
where Conn: AsyncConnectionCore, U: 'conn, Self: LoadQuery<'query, Conn, U> + 'query,

Executes the given query, returning a [Stream] with the returned rows. Read more
Source§

fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
where U: Send + 'conn, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Runs the command, and returns the affected row. Read more
Source§

fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
where U: Send, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Runs the command, returning an Vec with the affected rows. Read more
Source§

fn first<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<<Self::Output as LoadQuery<'query, Conn, U>>::LoadFuture<'conn>, LoadNext<Pin<Box<<Self::Output as LoadQuery<'query, Conn, U>>::Stream<'conn>>>>>
where U: Send + 'conn, Conn: AsyncConnectionCore, Self: LimitDsl, Self::Output: LoadQuery<'query, Conn, U> + Send + 'query,

Attempts to load a single record. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scoped for T
where T: Send + Sync + 'static,

Source§

fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>

Open a deferred ScopeQuery for this type. Resolves the registered scope at .load() time, not here.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP
Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,