use std::{cell::RefCell, error::Error, fmt, io::Write};
pub use ntex_http::error::Error as HttpError;
pub use serde_json::error::Error as JsonError;
#[cfg(feature = "url")]
pub use url_pkg::ParseError as UrlParseError;
use crate::http::body::Body;
use crate::http::{StatusCode, error, header};
use crate::util::{BytesMut, Either};
pub use crate::http::error::BlockingError;
pub use crate::web::error_default::DefaultError;
use super::HttpResponse;
pub trait WebResponseError<St, Err>: Error + 'static {
fn error_response(&self, _: &St) -> HttpResponse {
HttpResponse::render_with(StatusCode::INTERNAL_SERVER_ERROR, &self)
}
fn into(self) -> Box<dyn WebResponseError<St, Err>>
where
Self: Sized,
{
Box::new(self)
}
}
pub struct WebError<St, Err>(pub(crate) Box<dyn WebResponseError<St, Err>>);
impl<St: 'static, Err: 'static> WebError<St, Err> {
pub fn from_err<E: WebResponseError<St, Err>>(err: E) -> Self {
Self(err.into())
}
}
impl<St: 'static, Err: 'static> WebResponseError<St, Err> for WebError<St, Err> {
fn error_response(&self, st: &St) -> HttpResponse {
self.0.error_response(st)
}
fn into(self) -> Box<dyn WebResponseError<St, Err>> {
self.0
}
}
impl<St, Err> Error for WebError<St, Err> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.0.source()
}
}
impl<St, Err> crate::http::error::ResponseError for WebError<St, Err> {
fn error_response(&self) -> HttpResponse {
HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR)
}
}
impl<St, Err> fmt::Display for WebError<St, Err> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl<St, Err> fmt::Debug for WebError<St, Err> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "web::WebError({})", self.0)
}
}
impl<E, St, Err> WebResponseError<St, Err> for crate::error::Error<E>
where
E: WebResponseError<St, Err> + Clone,
{
fn error_response(&self, st: &St) -> HttpResponse {
(**self).error_response(st)
}
}
impl<St, Err> WebResponseError<St, Err> for std::convert::Infallible {}
impl<St, Err, A, B> WebResponseError<St, Err> for Either<A, B>
where
A: WebResponseError<St, Err>,
B: WebResponseError<St, Err>,
{
fn error_response(&self, st: &St) -> HttpResponse {
match self {
Either::Left(a) => a.error_response(st),
Either::Right(b) => b.error_response(st),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
pub enum StateExtractorError {
#[error("App state is not configured, to configure use App::state()")]
NotConfigured,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
pub enum UrlGenerationError {
#[error("Resource not found")]
ResourceNotFound,
#[error("Not all path pattern covered")]
NotEnoughElements,
#[cfg(feature = "url")]
#[error("{0}")]
ParseError(
#[from]
#[source]
UrlParseError,
),
}
#[derive(Debug, thiserror::Error)]
pub enum UrlencodedError {
#[error("Cannot decode chunked transfer encoding")]
Chunked,
#[error(
"Urlencoded payload size is bigger ({size} bytes) than allowed (default: {limit} bytes)"
)]
Overflow { size: usize, limit: usize },
#[error("Payload size is unknown")]
UnknownLength,
#[error("Content type error")]
ContentType,
#[error("Parse error")]
Parse,
#[error("Error that occur during reading payload: {0}")]
Payload(
#[from]
#[source]
error::PayloadError,
),
}
#[derive(Debug, thiserror::Error)]
pub enum JsonPayloadError {
#[error("Json payload size is bigger than allowed")]
Overflow,
#[error("Content type error")]
ContentType,
#[error("Json deserialize error: {0}")]
Deserialize(
#[from]
#[source]
serde_json::error::Error,
),
#[error("Error that occur during reading payload: {0}")]
Payload(
#[from]
#[source]
error::PayloadError,
),
}
#[derive(Debug, thiserror::Error)]
pub enum PathError {
#[error("Path deserialize error: {0}")]
Deserialize(
#[from]
#[source]
serde::de::value::Error,
),
}
#[derive(Debug, thiserror::Error)]
pub enum QueryPayloadError {
#[error("Query deserialize error: {0}")]
Deserialize(
#[from]
#[source]
serde::de::value::Error,
),
}
#[derive(Debug, thiserror::Error)]
pub enum PayloadError {
#[error("{0:?}")]
Http(
#[from]
#[source]
error::HttpError,
),
#[error("{0}")]
Payload(
#[from]
#[source]
error::PayloadError,
),
#[error("{0}")]
ContentType(
#[from]
#[source]
error::ContentTypeError,
),
#[error("Cannot decode body")]
Decoding,
}
pub struct InternalError<T> {
cause: T,
status: InternalErrorType,
}
enum InternalErrorType {
Status(StatusCode),
Response(RefCell<Option<HttpResponse>>),
}
impl<T> InternalError<T> {
pub fn default(cause: T, status: StatusCode) -> Self {
InternalError {
cause,
status: InternalErrorType::Status(status),
}
}
}
impl<T> InternalError<T> {
pub fn new(cause: T, status: StatusCode) -> Self {
InternalError {
cause,
status: InternalErrorType::Status(status),
}
}
pub fn from_response(cause: T, response: HttpResponse) -> Self {
InternalError {
cause,
status: InternalErrorType::Response(RefCell::new(Some(response))),
}
}
}
impl<T> fmt::Debug for InternalError<T>
where
T: fmt::Debug + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "web::InternalError({:?})", self.cause)
}
}
impl<T> fmt::Display for InternalError<T>
where
T: fmt::Display + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.cause, f)
}
}
impl<T: fmt::Display + fmt::Debug + 'static> std::error::Error for InternalError<T> {}
impl<T> crate::http::error::ResponseError for InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
fn error_response(&self) -> HttpResponse {
match self.status {
InternalErrorType::Status(st) => {
let mut res = HttpResponse::new(st);
let mut buf = BytesMut::new();
let _ = write!(&mut buf, "{self}");
res.headers_mut().insert(
header::CONTENT_TYPE,
header::HeaderValue::from_static("text/plain; charset=utf-8"),
);
res.set_body(Body::from(buf))
}
InternalErrorType::Response(ref resp) => {
if let Some(resp) = resp.borrow_mut().take() {
resp
} else {
HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR)
}
}
}
}
}
#[allow(non_snake_case)]
pub fn ErrorBadRequest<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::BAD_REQUEST)
}
#[allow(non_snake_case)]
pub fn ErrorUnauthorized<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::UNAUTHORIZED)
}
#[allow(non_snake_case)]
pub fn ErrorPaymentRequired<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::PAYMENT_REQUIRED)
}
#[allow(non_snake_case)]
pub fn ErrorForbidden<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::FORBIDDEN)
}
#[allow(non_snake_case)]
pub fn ErrorNotFound<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::NOT_FOUND)
}
#[allow(non_snake_case)]
pub fn ErrorMethodNotAllowed<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::METHOD_NOT_ALLOWED)
}
#[allow(non_snake_case)]
pub fn ErrorNotAcceptable<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::NOT_ACCEPTABLE)
}
#[allow(non_snake_case)]
pub fn ErrorProxyAuthenticationRequired<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::PROXY_AUTHENTICATION_REQUIRED)
}
#[allow(non_snake_case)]
pub fn ErrorRequestTimeout<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::REQUEST_TIMEOUT)
}
#[allow(non_snake_case)]
pub fn ErrorConflict<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::CONFLICT)
}
#[allow(non_snake_case)]
pub fn ErrorGone<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::GONE)
}
#[allow(non_snake_case)]
pub fn ErrorLengthRequired<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::LENGTH_REQUIRED)
}
#[allow(non_snake_case)]
pub fn ErrorPayloadTooLarge<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::PAYLOAD_TOO_LARGE)
}
#[allow(non_snake_case)]
pub fn ErrorUriTooLong<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::URI_TOO_LONG)
}
#[allow(non_snake_case)]
pub fn ErrorUnsupportedMediaType<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::UNSUPPORTED_MEDIA_TYPE)
}
#[allow(non_snake_case)]
pub fn ErrorRangeNotSatisfiable<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::RANGE_NOT_SATISFIABLE)
}
#[allow(non_snake_case)]
pub fn ErrorImATeapot<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::IM_A_TEAPOT)
}
#[allow(non_snake_case)]
pub fn ErrorMisdirectedRequest<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::MISDIRECTED_REQUEST)
}
#[allow(non_snake_case)]
pub fn ErrorUnprocessableEntity<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::UNPROCESSABLE_ENTITY)
}
#[allow(non_snake_case)]
pub fn ErrorLocked<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::LOCKED)
}
#[allow(non_snake_case)]
pub fn ErrorFailedDependency<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::FAILED_DEPENDENCY)
}
#[allow(non_snake_case)]
pub fn ErrorUpgradeRequired<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::UPGRADE_REQUIRED)
}
#[allow(non_snake_case)]
pub fn ErrorPreconditionFailed<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::PRECONDITION_FAILED)
}
#[allow(non_snake_case)]
pub fn ErrorPreconditionRequired<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::PRECONDITION_REQUIRED)
}
#[allow(non_snake_case)]
pub fn ErrorTooManyRequests<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::TOO_MANY_REQUESTS)
}
#[allow(non_snake_case)]
pub fn ErrorRequestHeaderFieldsTooLarge<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE)
}
#[allow(non_snake_case)]
pub fn ErrorUnavailableForLegalReasons<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS)
}
#[allow(non_snake_case)]
pub fn ErrorExpectationFailed<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::EXPECTATION_FAILED)
}
#[allow(non_snake_case)]
pub fn ErrorInternalServerError<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::INTERNAL_SERVER_ERROR)
}
#[allow(non_snake_case)]
pub fn ErrorNotImplemented<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::NOT_IMPLEMENTED)
}
#[allow(non_snake_case)]
pub fn ErrorBadGateway<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::BAD_GATEWAY)
}
#[allow(non_snake_case)]
pub fn ErrorServiceUnavailable<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::SERVICE_UNAVAILABLE)
}
#[allow(non_snake_case)]
pub fn ErrorGatewayTimeout<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::GATEWAY_TIMEOUT)
}
#[allow(non_snake_case)]
pub fn ErrorHttpVersionNotSupported<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::HTTP_VERSION_NOT_SUPPORTED)
}
#[allow(non_snake_case)]
pub fn ErrorVariantAlsoNegotiates<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::VARIANT_ALSO_NEGOTIATES)
}
#[allow(non_snake_case)]
pub fn ErrorInsufficientStorage<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::INSUFFICIENT_STORAGE)
}
#[allow(non_snake_case)]
pub fn ErrorLoopDetected<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::LOOP_DETECTED)
}
#[allow(non_snake_case)]
pub fn ErrorNotExtended<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::NOT_EXTENDED)
}
#[allow(non_snake_case)]
pub fn ErrorNetworkAuthenticationRequired<T>(err: T) -> InternalError<T>
where
T: fmt::Debug + fmt::Display + 'static,
{
InternalError::new(err, StatusCode::NETWORK_AUTHENTICATION_REQUIRED)
}
#[cfg(test)]
mod tests {
use std::io;
use super::*;
use crate::client::error::{ClientError, ConnectError};
use crate::{http, web::WebError};
#[test]
fn test_into_error() {
let e = WebError::<(), _>::from_err(UrlencodedError::UnknownLength);
let s = format!("{e}");
assert!(s.contains("Payload size is unknown"), "{}", s);
let s = format!("{e:?}");
assert!(s.contains("web::WebError"), "{}", s);
let res = crate::http::ResponseError::error_response(&e);
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
let res = WebResponseError::<(), DefaultError>::error_response(
&UrlencodedError::UnknownLength,
&(),
);
assert_eq!(res.status(), StatusCode::LENGTH_REQUIRED);
}
#[test]
fn test_other_errors() {
use crate::util::timeout::TimeoutError;
let err = TimeoutError::<UrlencodedError>::Timeout;
assert_eq!(
WebResponseError::<(), DefaultError>::error_response(&err, &(),).status(),
StatusCode::GATEWAY_TIMEOUT
);
let err = TimeoutError::<UrlencodedError>::Service(UrlencodedError::Chunked);
assert_eq!(
WebResponseError::<(), DefaultError>::error_response(&err, &(),).status(),
StatusCode::BAD_REQUEST
);
let resp =
WebResponseError::error_response(&ClientError::Connect(ConnectError::Timeout), &());
assert_eq!(resp.status(), StatusCode::GATEWAY_TIMEOUT);
let resp = WebResponseError::error_response(
&ClientError::Connect(ConnectError::SslIsNotSupported),
&(),
);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let resp = WebResponseError::error_response(&ClientError::TunnelNotSupported, &());
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
#[cfg(feature = "cookie")]
{
let resp: HttpResponse =
WebResponseError::error_response(&coo_kie::ParseError::EmptyName, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
let resp = WebResponseError::error_response(
&crate::http::error::ContentTypeError::ParseError,
&(),
);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let err = serde_urlencoded::from_str::<i32>("bad query").unwrap_err();
let resp = WebResponseError::error_response(&err, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let err = PayloadError::Decoding;
let resp = WebResponseError::error_response(&err, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
#[allow(invalid_from_utf8)]
let err = std::str::from_utf8(b"\xF0").unwrap_err();
let resp = WebResponseError::error_response(&err, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let err = http::error::PayloadError::EncodingCorrupted;
let resp = WebResponseError::error_response(&err, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
#[test]
fn test_either_error() {
let err: Either<ClientError, PayloadError> = Either::Left(ClientError::TunnelNotSupported);
let resp = WebResponseError::error_response(&err, &());
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
let err: Either<ClientError, PayloadError> = Either::Right(PayloadError::Decoding);
let resp = WebResponseError::error_response(&err, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
#[test]
fn test_io_error() {
assert_eq!(
StatusCode::NOT_FOUND,
WebResponseError::error_response(&io::Error::new(io::ErrorKind::NotFound, ""), &(),)
.status(),
);
assert_eq!(
StatusCode::FORBIDDEN,
WebResponseError::error_response(
&io::Error::new(io::ErrorKind::PermissionDenied, ""),
&(),
)
.status(),
);
assert_eq!(
StatusCode::INTERNAL_SERVER_ERROR,
WebResponseError::error_response(&io::Error::other(""), &(),).status(),
);
}
#[test]
fn test_urlencoded_error() {
let resp: HttpResponse =
WebResponseError::error_response(&UrlencodedError::Overflow { size: 0, limit: 0 }, &());
assert_eq!(resp.status(), StatusCode::PAYLOAD_TOO_LARGE);
let resp: HttpResponse =
WebResponseError::error_response(&UrlencodedError::UnknownLength, &());
assert_eq!(resp.status(), StatusCode::LENGTH_REQUIRED);
let resp: HttpResponse =
WebResponseError::error_response(&UrlencodedError::ContentType, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
#[test]
fn test_json_payload_error() {
let resp: HttpResponse = WebResponseError::error_response(&JsonPayloadError::Overflow, &());
assert_eq!(resp.status(), StatusCode::PAYLOAD_TOO_LARGE);
let resp: HttpResponse =
WebResponseError::error_response(&JsonPayloadError::ContentType, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
#[test]
fn test_query_payload_error() {
let err = QueryPayloadError::Deserialize(
serde_urlencoded::from_str::<i32>("bad query").unwrap_err(),
);
let resp: HttpResponse = WebResponseError::error_response(&err, &());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
#[test]
fn test_path_error() {
let err =
PathError::Deserialize(serde_urlencoded::from_str::<i32>("bad path").unwrap_err());
let resp: HttpResponse = WebResponseError::error_response(&err, &());
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
}
#[test]
fn test_handshake_error() {
use crate::ws::error::HandshakeError;
let resp = WebResponseError::<_, DefaultError>::error_response(
&HandshakeError::GetMethodRequired,
&(),
);
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
let resp = WebResponseError::<_, DefaultError>::error_response(
&HandshakeError::NoWebsocketUpgrade,
&(),
);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let resp = WebResponseError::<_, DefaultError>::error_response(
&HandshakeError::NoConnectionUpgrade,
&(),
);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let resp = WebResponseError::<_, DefaultError>::error_response(
&HandshakeError::NoVersionHeader,
&(),
);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let resp = WebResponseError::<_, DefaultError>::error_response(
&HandshakeError::UnsupportedVersion,
&(),
);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let resp = WebResponseError::<_, DefaultError>::error_response(
&HandshakeError::BadWebsocketKey,
&(),
);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
#[test]
fn test_error_helpers() {
let err = ErrorBadRequest::<_>("err");
assert!(format!("{err:?}").contains("web::InternalError"));
let err: InternalError<_> =
InternalError::from_response("err", HttpResponse::BadRequest().build());
let r = err.error_response(&());
assert_eq!(r.status(), StatusCode::BAD_REQUEST);
let r = ErrorBadRequest::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::BAD_REQUEST);
let r = ErrorUnauthorized::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::UNAUTHORIZED);
let r = ErrorPaymentRequired::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::PAYMENT_REQUIRED);
let r = ErrorForbidden::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::FORBIDDEN);
let r = ErrorNotFound::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::NOT_FOUND);
let r = ErrorMethodNotAllowed::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::METHOD_NOT_ALLOWED);
let r = ErrorNotAcceptable::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::NOT_ACCEPTABLE);
let r = ErrorProxyAuthenticationRequired::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::PROXY_AUTHENTICATION_REQUIRED);
let r = ErrorRequestTimeout::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::REQUEST_TIMEOUT);
let r = ErrorConflict::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::CONFLICT);
let r = ErrorGone::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::GONE);
let r = ErrorLengthRequired::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::LENGTH_REQUIRED);
let r = ErrorPreconditionFailed::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::PRECONDITION_FAILED);
let r = ErrorPayloadTooLarge::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::PAYLOAD_TOO_LARGE);
let r = ErrorUriTooLong::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::URI_TOO_LONG);
let r = ErrorUnsupportedMediaType::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE);
let r = ErrorRangeNotSatisfiable::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::RANGE_NOT_SATISFIABLE);
let r = ErrorExpectationFailed::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::EXPECTATION_FAILED);
let r = ErrorImATeapot::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::IM_A_TEAPOT);
let r = ErrorMisdirectedRequest::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::MISDIRECTED_REQUEST);
let r = ErrorUnprocessableEntity::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::UNPROCESSABLE_ENTITY);
let r = ErrorLocked::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::LOCKED);
let r = ErrorFailedDependency::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::FAILED_DEPENDENCY);
let r = ErrorUpgradeRequired::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::UPGRADE_REQUIRED);
let r = ErrorPreconditionRequired::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::PRECONDITION_REQUIRED);
let r = ErrorTooManyRequests::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::TOO_MANY_REQUESTS);
let r = ErrorRequestHeaderFieldsTooLarge::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE);
let r = ErrorUnavailableForLegalReasons::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS);
let r = ErrorInternalServerError::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::INTERNAL_SERVER_ERROR);
let r = ErrorNotImplemented::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::NOT_IMPLEMENTED);
let r = ErrorBadGateway::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::BAD_GATEWAY);
let r = ErrorServiceUnavailable::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::SERVICE_UNAVAILABLE);
let r = ErrorGatewayTimeout::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::GATEWAY_TIMEOUT);
let r = ErrorHttpVersionNotSupported::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::HTTP_VERSION_NOT_SUPPORTED);
let r = ErrorVariantAlsoNegotiates::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::VARIANT_ALSO_NEGOTIATES);
let r = ErrorInsufficientStorage::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::INSUFFICIENT_STORAGE);
let r = ErrorLoopDetected::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::LOOP_DETECTED);
let r = ErrorNotExtended::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::NOT_EXTENDED);
let r = ErrorNetworkAuthenticationRequired::<_>("err").error_response(&());
assert_eq!(r.status(), StatusCode::NETWORK_AUTHENTICATION_REQUIRED);
}
}