mirror of https://github.com/fafhrd91/actix-web
awc: Convert from `derive_more` to `thiserror`
The `thiserror` has the advantage of implementing `std::error::Error` and it integrates better with the Rust ecosystem. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
This commit is contained in:
parent
d2259b57dc
commit
e71a7f3cf2
|
@ -41,7 +41,6 @@ actix-rt = "1.0.0"
|
||||||
|
|
||||||
base64 = "0.11"
|
base64 = "0.11"
|
||||||
bytes = "0.5.3"
|
bytes = "0.5.3"
|
||||||
derive_more = "0.99.2"
|
|
||||||
futures-core = "0.3.1"
|
futures-core = "0.3.1"
|
||||||
log =" 0.4"
|
log =" 0.4"
|
||||||
mime = "0.3"
|
mime = "0.3"
|
||||||
|
@ -52,6 +51,7 @@ serde_json = "1.0"
|
||||||
serde_urlencoded = "0.6.1"
|
serde_urlencoded = "0.6.1"
|
||||||
open-ssl = { version="0.10", package="openssl", optional = true }
|
open-ssl = { version="0.10", package="openssl", optional = true }
|
||||||
rust-tls = { version = "0.17.0", package="rustls", optional = true, features = ["dangerous_configuration"] }
|
rust-tls = { version = "0.17.0", package="rustls", optional = true, features = ["dangerous_configuration"] }
|
||||||
|
thiserror = "1.0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-connect = { version = "2.0.0-alpha.2", features=["openssl"] }
|
actix-connect = { version = "2.0.0-alpha.2", features=["openssl"] }
|
||||||
|
|
|
@ -11,35 +11,35 @@ use actix_http::ResponseError;
|
||||||
use serde_json::error::Error as JsonError;
|
use serde_json::error::Error as JsonError;
|
||||||
|
|
||||||
use actix_http::http::{header::HeaderValue, StatusCode};
|
use actix_http::http::{header::HeaderValue, StatusCode};
|
||||||
use derive_more::{Display, From};
|
use thiserror::Error;
|
||||||
|
|
||||||
/// Websocket client error
|
/// Websocket client error
|
||||||
#[derive(Debug, Display, From)]
|
#[derive(Debug, Error)]
|
||||||
pub enum WsClientError {
|
pub enum WsClientError {
|
||||||
/// Invalid response status
|
/// Invalid response status
|
||||||
#[display(fmt = "Invalid response status")]
|
#[error("Invalid response status")]
|
||||||
InvalidResponseStatus(StatusCode),
|
InvalidResponseStatus(StatusCode),
|
||||||
/// Invalid upgrade header
|
/// Invalid upgrade header
|
||||||
#[display(fmt = "Invalid upgrade header")]
|
#[error("Invalid upgrade header")]
|
||||||
InvalidUpgradeHeader,
|
InvalidUpgradeHeader,
|
||||||
/// Invalid connection header
|
/// Invalid connection header
|
||||||
#[display(fmt = "Invalid connection header")]
|
#[error("Invalid connection header")]
|
||||||
InvalidConnectionHeader(HeaderValue),
|
InvalidConnectionHeader(HeaderValue),
|
||||||
/// Missing CONNECTION header
|
/// Missing CONNECTION header
|
||||||
#[display(fmt = "Missing CONNECTION header")]
|
#[error("Missing CONNECTION header")]
|
||||||
MissingConnectionHeader,
|
MissingConnectionHeader,
|
||||||
/// Missing SEC-WEBSOCKET-ACCEPT header
|
/// Missing SEC-WEBSOCKET-ACCEPT header
|
||||||
#[display(fmt = "Missing SEC-WEBSOCKET-ACCEPT header")]
|
#[error("Missing SEC-WEBSOCKET-ACCEPT header")]
|
||||||
MissingWebSocketAcceptHeader,
|
MissingWebSocketAcceptHeader,
|
||||||
/// Invalid challenge response
|
/// Invalid challenge response
|
||||||
#[display(fmt = "Invalid challenge response")]
|
#[error("Invalid challenge response")]
|
||||||
InvalidChallengeResponse(String, HeaderValue),
|
InvalidChallengeResponse(String, HeaderValue),
|
||||||
/// Protocol error
|
/// Protocol error
|
||||||
#[display(fmt = "{}", _0)]
|
#[error(transparent)]
|
||||||
Protocol(WsProtocolError),
|
Protocol(#[from] WsProtocolError),
|
||||||
/// Send request error
|
/// Send request error
|
||||||
#[display(fmt = "{}", _0)]
|
#[error(transparent)]
|
||||||
SendRequest(SendRequestError),
|
SendRequest(#[from] SendRequestError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<InvalidUrl> for WsClientError {
|
impl From<InvalidUrl> for WsClientError {
|
||||||
|
@ -55,17 +55,17 @@ impl From<HttpError> for WsClientError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of errors that can occur during parsing json payloads
|
/// A set of errors that can occur during parsing json payloads
|
||||||
#[derive(Debug, Display, From)]
|
#[derive(Debug, Error)]
|
||||||
pub enum JsonPayloadError {
|
pub enum JsonPayloadError {
|
||||||
/// Content type error
|
/// Content type error
|
||||||
#[display(fmt = "Content type error")]
|
#[error("Content type error")]
|
||||||
ContentType,
|
ContentType,
|
||||||
/// Deserialize error
|
/// Deserialize error
|
||||||
#[display(fmt = "Json deserialize error: {}", _0)]
|
#[error("Json deserialize error: {0}")]
|
||||||
Deserialize(JsonError),
|
Deserialize(#[from] JsonError),
|
||||||
/// Payload error
|
/// Payload error
|
||||||
#[display(fmt = "Error that occur during reading payload: {}", _0)]
|
#[error("Error that occur during reading payload: {0}")]
|
||||||
Payload(PayloadError),
|
Payload(#[from] PayloadError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `InternalServerError` for `JsonPayloadError`
|
/// Return `InternalServerError` for `JsonPayloadError`
|
||||||
|
|
|
@ -6,9 +6,9 @@ use std::time::Duration;
|
||||||
|
|
||||||
use actix_rt::time::{delay_for, Delay};
|
use actix_rt::time::{delay_for, Delay};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use derive_more::From;
|
|
||||||
use futures_core::{Future, Stream};
|
use futures_core::{Future, Stream};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use actix_http::body::{Body, BodyStream};
|
use actix_http::body::{Body, BodyStream};
|
||||||
use actix_http::http::header::{self, IntoHeaderValue};
|
use actix_http::http::header::{self, IntoHeaderValue};
|
||||||
|
@ -26,10 +26,12 @@ use crate::error::{FreezeRequestError, InvalidUrl, SendRequestError};
|
||||||
use crate::response::ClientResponse;
|
use crate::response::ClientResponse;
|
||||||
use crate::ClientConfig;
|
use crate::ClientConfig;
|
||||||
|
|
||||||
#[derive(Debug, From)]
|
#[derive(Debug, Error)]
|
||||||
pub(crate) enum PrepForSendingError {
|
pub(crate) enum PrepForSendingError {
|
||||||
Url(InvalidUrl),
|
#[error(transparent)]
|
||||||
Http(HttpError),
|
Url(#[from] InvalidUrl),
|
||||||
|
#[error(transparent)]
|
||||||
|
Http(#[from] HttpError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<FreezeRequestError> for PrepForSendingError {
|
impl Into<FreezeRequestError> for PrepForSendingError {
|
||||||
|
|
Loading…
Reference in New Issue