1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 22:49:21 +02:00

refactor ResponseError trait

This commit is contained in:
Nikolay Kim
2019-11-26 16:07:39 +06:00
parent 4dc31aac93
commit f73f97353b
11 changed files with 105 additions and 111 deletions

View File

@ -7,8 +7,7 @@ use trust_dns_resolver::error::ResolveError;
use open_ssl::ssl::{Error as SslError, HandshakeError};
use crate::error::{Error, ParseError, ResponseError};
use crate::http::Error as HttpError;
use crate::response::Response;
use crate::http::{Error as HttpError, StatusCode};
/// A set of errors that can occur while connecting to an HTTP host
#[derive(Debug, Display, From)]
@ -117,15 +116,14 @@ pub enum SendRequestError {
/// Convert `SendRequestError` to a server `Response`
impl ResponseError for SendRequestError {
fn error_response(&self) -> Response {
fn status_code(&self) -> StatusCode {
match *self {
SendRequestError::Connect(ConnectError::Timeout) => {
Response::GatewayTimeout()
StatusCode::GATEWAY_TIMEOUT
}
SendRequestError::Connect(_) => Response::BadGateway(),
_ => Response::InternalServerError(),
SendRequestError::Connect(_) => StatusCode::BAD_REQUEST,
_ => StatusCode::INTERNAL_SERVER_ERROR,
}
.into()
}
}