pub enum FrameworkError {
ServiceNotFound {
type_name: &'static str,
},
ParamError {
param_name: String,
},
ValidationError {
field: String,
message: String,
},
Database(String),
Internal {
message: String,
},
Domain {
message: String,
status_code: u16,
},
}Expand description
Framework-wide error type
This enum represents all possible errors that can occur in the framework.
It implements From<FrameworkError> for Response so errors can be propagated
using the ? operator in controller handlers.
§Example
use kit::{App, FrameworkError, Response};
pub async fn index(_req: Request) -> Response {
let service = App::resolve::<MyService>()?; // Returns FrameworkError on failure
// ...
}§Automatic Error Conversion
FrameworkError implements From for common error types, allowing seamless
use of the ? operator:
use kit::{DB, FrameworkError};
use sea_orm::ActiveModelTrait;
pub async fn create_todo() -> Result<Todo, FrameworkError> {
let todo = new_todo.insert(&*DB::get()?).await?; // DbErr converts automatically!
Ok(todo)
}Variants§
ServiceNotFound
Service not found in the dependency injection container
ParamError
Parameter extraction failed (missing or invalid parameter)
ValidationError
Validation error
Database(String)
Database error
Internal
Generic internal server error
Domain
Domain/application error with custom status code
Used for user-defined domain errors that need custom HTTP status codes.
Implementations§
Source§impl FrameworkError
impl FrameworkError
Sourcepub fn service_not_found<T: ?Sized>() -> Self
pub fn service_not_found<T: ?Sized>() -> Self
Create a ServiceNotFound error for a given type
Sourcepub fn validation(field: impl Into<String>, message: impl Into<String>) -> Self
pub fn validation(field: impl Into<String>, message: impl Into<String>) -> Self
Create a ValidationError
Sourcepub fn domain(message: impl Into<String>, status_code: u16) -> Self
pub fn domain(message: impl Into<String>, status_code: u16) -> Self
Create a Domain error with custom status code
Sourcepub fn status_code(&self) -> u16
pub fn status_code(&self) -> u16
Get the HTTP status code for this error
Trait Implementations§
Source§impl Clone for FrameworkError
impl Clone for FrameworkError
Source§fn clone(&self) -> FrameworkError
fn clone(&self) -> FrameworkError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FrameworkError
impl Debug for FrameworkError
Source§impl Display for FrameworkError
impl Display for FrameworkError
Source§impl Error for FrameworkError
impl Error for FrameworkError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<AppError> for FrameworkError
impl From<AppError> for FrameworkError
Source§impl From<DbErr> for FrameworkError
impl From<DbErr> for FrameworkError
Source§impl From<FrameworkError> for HttpResponse
Auto-convert FrameworkError to HttpResponse
impl From<FrameworkError> for HttpResponse
Auto-convert FrameworkError to HttpResponse
This enables using the ? operator in controller handlers to propagate
framework errors as appropriate HTTP responses.
Source§fn from(err: FrameworkError) -> HttpResponse
fn from(err: FrameworkError) -> HttpResponse
Source§impl From<ParamError> for FrameworkError
impl From<ParamError> for FrameworkError
Source§fn from(err: ParamError) -> FrameworkError
fn from(err: ParamError) -> FrameworkError
Auto Trait Implementations§
impl Freeze for FrameworkError
impl RefUnwindSafe for FrameworkError
impl Send for FrameworkError
impl Sync for FrameworkError
impl Unpin for FrameworkError
impl UnwindSafe for FrameworkError
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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