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
impl Error
Sourcepub fn new<E>(kind: ErrorKind, error: E) -> Self
pub fn new<E>(kind: ErrorKind, error: E) -> Self
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);Sourcepub fn kind(&self) -> ErrorKind
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"),
}
}Sourcepub fn error_code(&self) -> &'static str
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.
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Returns the HTTP status code for this error.
Sourcepub fn to_error_response(&self) -> ErrorResponse
pub fn to_error_response(&self) -> ErrorResponse
Converts the error into a structured error response.
Source§impl Error
impl Error
Sourcepub fn database_config(msg: impl Into<String>) -> Self
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.
Sourcepub fn authentication(msg: impl Into<String>) -> Self
pub fn authentication(msg: impl Into<String>) -> Self
Creates an authentication error.
Sourcepub fn invalid_input(msg: impl Into<String>) -> Self
pub fn invalid_input(msg: impl Into<String>) -> Self
Creates an invalid input error.