pub enum AppError {
BadRequest(String),
Unauthorized,
Forbidden,
NotFound(String),
Conflict(String),
UnprocessableEntity(String),
Internal(String),
}Expand description
A built-in typed error that maps common failure cases to standard HTTP status codes. Use it directly or as a model for your own error type.
§Example
use rust_web_server::error::{AppError, IntoResponse};
use rust_web_server::response::Response;
fn find_user(id: u64) -> Result<Response, AppError> {
if id == 0 {
return Err(AppError::NotFound("user not found".to_string()));
}
Err(AppError::Internal("db error".to_string()))
}
// In your controller:
// let response = find_user(id).unwrap_or_else(|e| e.into_response());Variants§
BadRequest(String)
400 Bad Request — malformed input.
401 Unauthorized — authentication is required.
Forbidden
403 Forbidden — authenticated but not permitted.
NotFound(String)
404 Not Found — the requested resource does not exist.
Conflict(String)
409 Conflict — the request conflicts with current state.
UnprocessableEntity(String)
422 Unprocessable Entity — input is syntactically valid but semantically wrong.
Internal(String)
500 Internal Server Error — unexpected server-side failure.
Trait Implementations§
impl Eq for AppError
Source§impl IntoResponse for AppError
impl IntoResponse for AppError
fn into_response(self) -> Response
impl StructuralPartialEq for AppError
Auto Trait Implementations§
impl Freeze for AppError
impl RefUnwindSafe for AppError
impl Send for AppError
impl Sync for AppError
impl Unpin for AppError
impl UnsafeUnpin for AppError
impl UnwindSafe for AppError
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.