Skip to main content

InternalError

Struct InternalError 

Source
pub struct InternalError<T> { /* private fields */ }
Expand description

Helper type that can wrap any error and generate custom response.

InternalError renders the wrapped error with a fixed status code, or with a prepared response, and implements WebResponseError for every error domain. The Error* helpers in this module, such as ErrorBadRequest, create InternalError values.

In the following example an io::Error is rendered as 400 Bad Request instead of the default 500 Internal Server Error.

use ntex::http::StatusCode;
use ntex::web::{self, InternalError};

async fn index() -> Result<&'static str, InternalError<std::io::Error>> {
    let err = std::io::Error::other("error");
    Err(InternalError::new(err, StatusCode::BAD_REQUEST))
}

let app = web::App::default().route("/", web::get().to(index));

Implementations§

Source§

impl<T> InternalError<T>

Source

pub fn default(cause: T, status: StatusCode) -> Self

Create InternalError instance

Source§

impl<T> InternalError<T>

Source

pub fn new(cause: T, status: StatusCode) -> Self

Create InternalError instance

Source

pub fn from_response(cause: T, response: HttpResponse) -> Self

Create InternalError with predefined Response.

Trait Implementations§

Source§

impl<T> Debug for InternalError<T>
where T: Debug + 'static,

Source§

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

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

impl<T> Display for InternalError<T>
where T: Display + 'static,

Source§

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

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

impl<T: Display + Debug + 'static> Error for InternalError<T>

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<St, T> Responder<St> for InternalError<T>
where St: State, T: Debug + Display + 'static,

Source§

async fn respond_to(self, st: &St, _: &HttpRequest) -> Response

Builds an HTTP response from this value.
Source§

fn with_status(self, status: StatusCode) -> CustomResponder<Self, St>
where Self: Sized,

Replaces the status code produced by this responder. Read more
Source§

fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self, St>

Sets a header on the response produced by this responder. Read more
Source§

impl<T> ResponseError for InternalError<T>
where T: Debug + Display + 'static,

Source§

fn error_response(&self) -> HttpResponse

Creates an HTTP response for this error. Read more
Source§

impl<St, Err, T> WebResponseError<St, Err> for InternalError<T>
where T: Debug + Display + 'static,

Source§

fn error_response(&self, _: &St) -> HttpResponse

Generate response for error Read more
Source§

fn into(self) -> Box<dyn WebResponseError<St, Err>>
where Self: Sized,

Convert the error into a boxed trait object. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for InternalError<T>

§

impl<T> !RefUnwindSafe for InternalError<T>

§

impl<T> !Send for InternalError<T>

§

impl<T> !Sync for InternalError<T>

§

impl<T> !UnwindSafe for InternalError<T>

§

impl<T> Unpin for InternalError<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for InternalError<T>
where T: UnsafeUnpin,

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, 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.