mirror of https://github.com/fafhrd91/actix-web
multipart: 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
e71a7f3cf2
commit
b4047ae053
|
@ -20,11 +20,11 @@ actix-web = { version = "3.0.0-alpha.1", default-features = false }
|
|||
actix-service = "1.0.1"
|
||||
actix-utils = "1.0.3"
|
||||
bytes = "0.5.3"
|
||||
derive_more = "0.99.2"
|
||||
httparse = "1.3"
|
||||
futures = "0.3.1"
|
||||
log = "0.4"
|
||||
mime = "0.3"
|
||||
thiserror = "1.0.11"
|
||||
twoway = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -2,39 +2,37 @@
|
|||
use actix_web::error::{ParseError, PayloadError};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::ResponseError;
|
||||
use derive_more::{Display, From};
|
||||
use thiserror::Error;
|
||||
|
||||
/// A set of errors that can occur during parsing multipart streams
|
||||
#[derive(Debug, Display, From)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum MultipartError {
|
||||
/// Content-Type header is not found
|
||||
#[display(fmt = "No Content-type header found")]
|
||||
#[error("No Content-type header found")]
|
||||
NoContentType,
|
||||
/// Can not parse Content-Type header
|
||||
#[display(fmt = "Can not parse Content-Type header")]
|
||||
#[error("Can not parse Content-Type header")]
|
||||
ParseContentType,
|
||||
/// Multipart boundary is not found
|
||||
#[display(fmt = "Multipart boundary is not found")]
|
||||
#[error("Multipart boundary is not found")]
|
||||
Boundary,
|
||||
/// Nested multipart is not supported
|
||||
#[display(fmt = "Nested multipart is not supported")]
|
||||
#[error("Nested multipart is not supported")]
|
||||
Nested,
|
||||
/// Multipart stream is incomplete
|
||||
#[display(fmt = "Multipart stream is incomplete")]
|
||||
#[error("Multipart stream is incomplete")]
|
||||
Incomplete,
|
||||
/// Error during field parsing
|
||||
#[display(fmt = "{}", _0)]
|
||||
Parse(ParseError),
|
||||
#[error(transparent)]
|
||||
Parse(#[from] ParseError),
|
||||
/// Payload error
|
||||
#[display(fmt = "{}", _0)]
|
||||
Payload(PayloadError),
|
||||
#[error(transparent)]
|
||||
Payload(#[from] PayloadError),
|
||||
/// Not consumed
|
||||
#[display(fmt = "Multipart stream is not consumed")]
|
||||
#[error("Multipart stream is not consumed")]
|
||||
NotConsumed,
|
||||
}
|
||||
|
||||
impl std::error::Error for MultipartError {}
|
||||
|
||||
/// Return `BadRequest` for `MultipartError`
|
||||
impl ResponseError for MultipartError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
|
|
Loading…
Reference in New Issue