mirror of
https://github.com/actix/actix-web.git
synced 2024-11-18 15:41:17 +00:00
Improve impl ResponseError
documentation (#1939)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
50309aa295
commit
deafb7c8b8
1 changed files with 21 additions and 14 deletions
|
@ -147,7 +147,10 @@ impl From<ResponseBuilder> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `GATEWAY_TIMEOUT` for `TimeoutError`
|
/// Inspects the underlying enum and returns an appropriate status code.
|
||||||
|
///
|
||||||
|
/// If the variant is [`TimeoutError::Service`], the error code of the service is returned.
|
||||||
|
/// Otherwise, [`StatusCode::GATEWAY_TIMEOUT`] is returned.
|
||||||
impl<E: ResponseError> ResponseError for TimeoutError<E> {
|
impl<E: ResponseError> ResponseError for TimeoutError<E> {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
match self {
|
match self {
|
||||||
|
@ -161,41 +164,44 @@ impl<E: ResponseError> ResponseError for TimeoutError<E> {
|
||||||
#[display(fmt = "UnknownError")]
|
#[display(fmt = "UnknownError")]
|
||||||
struct UnitError;
|
struct UnitError;
|
||||||
|
|
||||||
/// `InternalServerError` for `UnitError`
|
/// Returns [`StatusCode::INTERNAL_SERVER_ERROR`] for [`UnitError`].
|
||||||
impl ResponseError for UnitError {}
|
impl ResponseError for UnitError {}
|
||||||
|
|
||||||
/// `InternalServerError` for `JsonError`
|
/// Returns [`StatusCode::INTERNAL_SERVER_ERROR`] for [`JsonError`].
|
||||||
impl ResponseError for JsonError {}
|
impl ResponseError for JsonError {}
|
||||||
|
|
||||||
/// `InternalServerError` for `FormError`
|
/// Returns [`StatusCode::INTERNAL_SERVER_ERROR`] for [`FormError`].
|
||||||
impl ResponseError for FormError {}
|
impl ResponseError for FormError {}
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
/// `InternalServerError` for `openssl::ssl::Error`
|
/// Returns [`StatusCode::INTERNAL_SERVER_ERROR`] for [`actix_tls::accept::openssl::SslError`].
|
||||||
impl ResponseError for actix_tls::accept::openssl::SslError {}
|
impl ResponseError for actix_tls::accept::openssl::SslError {}
|
||||||
|
|
||||||
/// Return `BAD_REQUEST` for `de::value::Error`
|
/// Returns [`StatusCode::BAD_REQUEST`] for [`DeError`].
|
||||||
impl ResponseError for DeError {
|
impl ResponseError for DeError {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
StatusCode::BAD_REQUEST
|
StatusCode::BAD_REQUEST
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `InternalServerError` for `Canceled`
|
/// Returns [`StatusCode::INTERNAL_SERVER_ERROR`] for [`Canceled`].
|
||||||
impl ResponseError for Canceled {}
|
impl ResponseError for Canceled {}
|
||||||
|
|
||||||
/// Return `BAD_REQUEST` for `Utf8Error`
|
/// Returns [`StatusCode::BAD_REQUEST`] for [`Utf8Error`].
|
||||||
impl ResponseError for Utf8Error {
|
impl ResponseError for Utf8Error {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
StatusCode::BAD_REQUEST
|
StatusCode::BAD_REQUEST
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `InternalServerError` for `HttpError`,
|
/// Returns [`StatusCode::INTERNAL_SERVER_ERROR`] for [`HttpError`].
|
||||||
/// Response generation can return `HttpError`, so it is internal error
|
|
||||||
impl ResponseError for HttpError {}
|
impl ResponseError for HttpError {}
|
||||||
|
|
||||||
/// Return `InternalServerError` for `io::Error`
|
/// Inspects the underlying [`io::ErrorKind`] and returns an appropriate status code.
|
||||||
|
///
|
||||||
|
/// If the error is [`io::ErrorKind::NotFound`], [`StatusCode::NOT_FOUND`] is returned. If the
|
||||||
|
/// error is [`io::ErrorKind::PermissionDenied`], [`StatusCode::FORBIDDEN`] is returned. Otherwise,
|
||||||
|
/// [`StatusCode::INTERNAL_SERVER_ERROR`] is returned.
|
||||||
impl ResponseError for io::Error {
|
impl ResponseError for io::Error {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
|
@ -206,7 +212,7 @@ impl ResponseError for io::Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `BadRequest` for `InvalidHeaderValue`
|
/// Returns [`StatusCode::BAD_REQUEST`] for [`header::InvalidHeaderValue`].
|
||||||
impl ResponseError for header::InvalidHeaderValue {
|
impl ResponseError for header::InvalidHeaderValue {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
StatusCode::BAD_REQUEST
|
StatusCode::BAD_REQUEST
|
||||||
|
@ -963,8 +969,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "actors")]
|
#[cfg(feature = "actors")]
|
||||||
/// `InternalServerError` for `actix::MailboxError`
|
/// Returns [`StatusCode::INTERNAL_SERVER_ERROR`] for [`actix::MailboxError`].
|
||||||
/// This is supported on feature=`actors` only
|
///
|
||||||
|
/// This is only supported when the feature `actors` is enabled.
|
||||||
impl ResponseError for actix::MailboxError {}
|
impl ResponseError for actix::MailboxError {}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue