Error

Struct Error 

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

An error that can occur in the axum-conf library.

This is an opaque error type that wraps an underlying error source. Use Error::kind() to determine the category of error for matching, and the Display implementation to get a human-readable message.

§Creating Errors

Use the convenience constructors for common cases:

use axum_conf::Error;

let err = Error::internal("unexpected state");
let err = Error::invalid_input("missing required field");
let err = Error::database("connection timeout");

Or use Error::new() for full control:

use axum_conf::{Error, ErrorKind};

let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file missing");
let err = Error::new(ErrorKind::Io, io_err);

Implementations§

Source§

impl Error

Source

pub fn new<E>(kind: ErrorKind, error: E) -> Self
where E: Into<Box<dyn Error + Send + Sync + 'static>>,

Creates a new error with the given kind and source.

§Example
use axum_conf::{Error, ErrorKind};

let err = Error::new(ErrorKind::Internal, "something went wrong");
assert_eq!(err.kind(), ErrorKind::Internal);
Source

pub fn kind(&self) -> ErrorKind

Returns the kind of this error.

Use this to match on error categories:

use axum_conf::{Error, ErrorKind};

fn handle_error(err: Error) {
    match err.kind() {
        ErrorKind::Database => eprintln!("Database issue, will retry"),
        ErrorKind::InvalidInput => eprintln!("Bad request"),
        _ => eprintln!("Unexpected error"),
    }
}
Source

pub fn error_code(&self) -> &'static str

Returns the error code string for this error.

This is a stable identifier suitable for client-side error handling.

Source

pub fn status_code(&self) -> StatusCode

Returns the HTTP status code for this error.

Source

pub fn to_error_response(&self) -> ErrorResponse

Converts the error into a structured error response.

Source

pub fn into_inner(self) -> Box<dyn Error + Send + Sync + 'static>

Consumes the error and returns the inner error source.

Source§

impl Error

Source

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

Creates a database error.

Source

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

Creates a database configuration error.

This is a convenience method that creates a Database kind error with a “Database configuration error” prefix.

Source

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

Creates an authentication error.

Source

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

Creates a configuration error.

Source

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

Creates a TLS error.

Source

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

Creates an I/O error from a message.

Source

pub fn from_io(err: Error) -> Self

Creates an I/O error from a std::io::Error.

Source

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

Creates an invalid input error.

Source

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

Creates an internal error.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

Source§

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

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<InvalidHeaderValue> for Error

Source§

fn from(err: InvalidHeaderValue) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(err: ParseError) -> Self

Converts to this type from the input type.
Source§

impl From<VarError> for Error

Source§

fn from(err: VarError) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for Error

Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

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.

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> 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, 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<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