Skip to main content

FrameworkError

Enum FrameworkError 

Source
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

Fields

§type_name: &'static str

The type name of the service that was not found

§

ParamError

Parameter extraction failed (missing or invalid parameter)

Fields

§param_name: String

The name of the parameter that failed extraction

§

ValidationError

Validation error

Fields

§field: String

The field that failed validation

§message: String

The validation error message

§

Database(String)

Database error

§

Internal

Generic internal server error

Fields

§message: String

The error message

§

Domain

Domain/application error with custom status code

Used for user-defined domain errors that need custom HTTP status codes.

Fields

§message: String

The error message

§status_code: u16

HTTP status code

§

Validation(ValidationErrors)

Form validation errors (422 Unprocessable Entity)

Contains multiple field validation errors in Laravel/Inertia format.

§

Unauthorized

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.

Fields

§model_name: String

The name of the model that was not found

§

ParamParse

Parameter parse error (400 Bad Request)

Used when a path parameter cannot be parsed to the expected type.

Fields

§param: String

The parameter value that failed to parse

§expected_type: &'static str

The expected type (e.g., “i32”, “uuid”)

Implementations§

Source§

impl FrameworkError

Source

pub fn service_not_found<T: ?Sized>() -> Self

Create a ServiceNotFound error for a given type

Source

pub fn param(name: impl Into<String>) -> Self

Create a ParamError for a missing parameter

Source

pub fn validation(field: impl Into<String>, message: impl Into<String>) -> Self

Create a ValidationError

Source

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

Create a DatabaseError

Source

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

Create an Internal error

Source

pub fn domain(message: impl Into<String>, status_code: u16) -> Self

Create a Domain error with custom status code

Source

pub fn status_code(&self) -> u16

Get the HTTP status code for this error

Source

pub fn validation_errors(errors: ValidationErrors) -> Self

Create a Validation error from ValidationErrors struct

Source

pub fn model_not_found(name: impl Into<String>) -> Self

Create a ModelNotFound error (404)

Source

pub fn param_parse( param: impl Into<String>, expected_type: &'static str, ) -> Self

Create a ParamParse error (400)

Source

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

Source§

fn clone(&self) -> FrameworkError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FrameworkError

Source§

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

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

impl Display for FrameworkError

Source§

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

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

impl Error for FrameworkError

1.30.0 · 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<AppError> for FrameworkError

Source§

fn from(e: AppError) -> Self

Converts to this type from the input type.
Source§

impl From<DbErr> for FrameworkError

Source§

fn from(e: DbErr) -> Self

Converts to this type from the input type.
Source§

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

Converts to this type from the input type.
Source§

impl From<ParamError> for FrameworkError

Source§

fn from(err: ParamError) -> FrameworkError

Converts to this type from the input type.

Auto Trait Implementations§

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> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Container<T> for T
where T: Clone,

Source§

type Iter = Once<T>

An iterator over the items within this container, by value.
Source§

fn get_iter(&self) -> <T as Container<T>>::Iter

Iterate over the elements of the container (using internal iteration because GATs are unstable).
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP
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
Source§

impl<T> OrderedContainer<T> for T
where T: Clone,