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