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.
Each error_response() call builds a response with the status, headers,
and connection type of response. An empty or in-memory body is repeated
on every call. A streaming body can be sent only once: the first call
gets it and later calls get an empty body. Extensions are moved into the
first 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)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()