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"
|
||||
bytes = "0.5.3"
|
||||
derive_more = "0.99.2"
|
||||
futures-core = "0.3.1"
|
||||
log =" 0.4"
|
||||
mime = "0.3"
|
||||
|
@ -52,6 +51,7 @@ serde_json = "1.0"
|
|||
serde_urlencoded = "0.6.1"
|
||||
open-ssl = { version="0.10", package="openssl", optional = true }
|
||||
rust-tls = { version = "0.17.0", package="rustls", optional = true, features = ["dangerous_configuration"] }
|
||||
thiserror = "1.0.11"
|
||||
|
||||
[dev-dependencies]
|
||||
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 actix_http::http::{header::HeaderValue, StatusCode};
|
||||
use derive_more::{Display, From};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Websocket client error
|
||||
#[derive(Debug, Display, From)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WsClientError {
|
||||
/// Invalid response status
|
||||
#[display(fmt = "Invalid response status")]
|
||||
#[error("Invalid response status")]
|
||||
InvalidResponseStatus(StatusCode),
|
||||
/// Invalid upgrade header
|
||||
#[display(fmt = "Invalid upgrade header")]
|
||||
#[error("Invalid upgrade header")]
|
||||
InvalidUpgradeHeader,
|
||||
/// Invalid connection header
|
||||
#[display(fmt = "Invalid connection header")]
|
||||
#[error("Invalid connection header")]
|
||||
InvalidConnectionHeader(HeaderValue),
|
||||
/// Missing CONNECTION header
|
||||
#[display(fmt = "Missing CONNECTION header")]
|
||||
#[error("Missing CONNECTION header")]
|
||||
MissingConnectionHeader,
|
||||
/// Missing SEC-WEBSOCKET-ACCEPT header
|
||||
#[display(fmt = "Missing SEC-WEBSOCKET-ACCEPT header")]
|
||||
#[error("Missing SEC-WEBSOCKET-ACCEPT header")]
|
||||
MissingWebSocketAcceptHeader,
|
||||
/// Invalid challenge response
|
||||
#[display(fmt = "Invalid challenge response")]
|
||||
#[error("Invalid challenge response")]
|
||||
InvalidChallengeResponse(String, HeaderValue),
|
||||
/// Protocol error
|
||||
#[display(fmt = "{}", _0)]
|
||||
Protocol(WsProtocolError),
|
||||
#[error(transparent)]
|
||||
Protocol(#[from] WsProtocolError),
|
||||
/// Send request error
|
||||
#[display(fmt = "{}", _0)]
|
||||
SendRequest(SendRequestError),
|
||||
#[error(transparent)]
|
||||
SendRequest(#[from] SendRequestError),
|
||||
}
|
||||
|
||||
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
|
||||
#[derive(Debug, Display, From)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum JsonPayloadError {
|
||||
/// Content type error
|
||||
#[display(fmt = "Content type error")]
|
||||
#[error("Content type error")]
|
||||
ContentType,
|
||||
/// Deserialize error
|
||||
#[display(fmt = "Json deserialize error: {}", _0)]
|
||||
Deserialize(JsonError),
|
||||
#[error("Json deserialize error: {0}")]
|
||||
Deserialize(#[from] JsonError),
|
||||
/// Payload error
|
||||
#[display(fmt = "Error that occur during reading payload: {}", _0)]
|
||||
Payload(PayloadError),
|
||||
#[error("Error that occur during reading payload: {0}")]
|
||||
Payload(#[from] PayloadError),
|
||||
}
|
||||
|
||||
/// Return `InternalServerError` for `JsonPayloadError`
|
||||
|
|
|
@ -6,9 +6,9 @@ use std::time::Duration;
|
|||
|
||||
use actix_rt::time::{delay_for, Delay};
|
||||
use bytes::Bytes;
|
||||
use derive_more::From;
|
||||
use futures_core::{Future, Stream};
|
||||
use serde::Serialize;
|
||||
use thiserror::Error;
|
||||
|
||||
use actix_http::body::{Body, BodyStream};
|
||||
use actix_http::http::header::{self, IntoHeaderValue};
|
||||
|
@ -26,10 +26,12 @@ use crate::error::{FreezeRequestError, InvalidUrl, SendRequestError};
|
|||
use crate::response::ClientResponse;
|
||||
use crate::ClientConfig;
|
||||
|
||||
#[derive(Debug, From)]
|
||||
#[derive(Debug, Error)]
|
||||
pub(crate) enum PrepForSendingError {
|
||||
Url(InvalidUrl),
|
||||
Http(HttpError),
|
||||
#[error(transparent)]
|
||||
Url(#[from] InvalidUrl),
|
||||
#[error(transparent)]
|
||||
Http(#[from] HttpError),
|
||||
}
|
||||
|
||||
impl Into<FreezeRequestError> for PrepForSendingError {
|
||||
|
|
Loading…
Reference in New Issue