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,
},
Validation(ValidationErrors),
Unauthorized,
ModelNotFound {
model_name: String,
},
ParamParse {
param: String,
expected_type: &'static str,
},
}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 ferro_rs::{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 ferro_rs::{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.
Validation(ValidationErrors)
Form validation errors (422 Unprocessable Entity)
Contains multiple field validation errors in Laravel/Inertia format.
Authorization failed (403 Forbidden)
Used when FormRequest::authorize() returns false.
ModelNotFound
Model not found (404 Not Found)
Used when route model binding fails to find the requested resource.
ParamParse
Parameter parse error (400 Bad Request)
Used when a path parameter cannot be parsed to the expected type.
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
Sourcepub fn validation_errors(errors: ValidationErrors) -> Self
pub fn validation_errors(errors: ValidationErrors) -> Self
Create a Validation error from ValidationErrors struct
Sourcepub fn model_not_found(name: impl Into<String>) -> Self
pub fn model_not_found(name: impl Into<String>) -> Self
Create a ModelNotFound error (404)
Sourcepub fn param_parse(
param: impl Into<String>,
expected_type: &'static str,
) -> Self
pub fn param_parse( param: impl Into<String>, expected_type: &'static str, ) -> Self
Create a ParamParse error (400)
Sourcepub fn hint(&self) -> Option<String>
pub fn hint(&self) -> Option<String>
Returns an actionable hint guiding the developer toward a fix.
Hints are included in JSON error responses during development to help
developers quickly resolve common issues. Variants with user-provided
messages (Internal, Domain) or self-describing content (Validation,
ValidationError) return None.
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.
When a hint is available (via FrameworkError::hint()), the JSON response
includes a "hint" field with actionable guidance for the developer.
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 UnsafeUnpin 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.