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>
impl<T> InternalError<T>
Sourcepub fn default(cause: T, status: StatusCode) -> Self
pub fn default(cause: T, status: StatusCode) -> Self
Create InternalError instance
Source§impl<T> InternalError<T>
impl<T> InternalError<T>
Sourcepub fn new(cause: T, status: StatusCode) -> Self
pub fn new(cause: T, status: StatusCode) -> Self
Create InternalError instance
Sourcepub fn from_response(cause: T, response: HttpResponse) -> Self
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,
impl<T> Debug for InternalError<T>where
T: Debug + 'static,
Source§impl<T> Display for InternalError<T>where
T: Display + 'static,
impl<T> Display for InternalError<T>where
T: Display + 'static,
Source§impl<T: Display + Debug + 'static> Error for InternalError<T>
impl<T: Display + Debug + 'static> Error for InternalError<T>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl<St, T> Responder<St> for InternalError<T>
impl<St, T> Responder<St> for InternalError<T>
Source§async fn respond_to(self, st: &St, _: &HttpRequest) -> Response
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,
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>where
Self: Sized,
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self, St>where
Self: Sized,
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Sets a header on the response produced by this responder. Read more
Source§impl<T> ResponseError for InternalError<T>
impl<T> ResponseError for InternalError<T>
Source§fn error_response(&self) -> HttpResponse
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>
impl<St, Err, T> WebResponseError<St, Err> for InternalError<T>
Source§fn error_response(&self, _: &St) -> HttpResponse
fn error_response(&self, _: &St) -> HttpResponse
Generate response for error 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> 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