use axum::response::IntoResponse;
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "Cannot have two request body extractors for a single request"]
pub struct BodyAlreadyExtracted;
}
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "Headers taken by other extractor"]
pub struct HeadersAlreadyExtracted;
}
define_rejection! {
#[status = BAD_REQUEST]
#[body = "Request deserialize failed"]
pub struct Deserialize(Error);
}
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "Response serialize failed"]
pub struct Serialize(Error);
}
define_rejection! {
#[status = BAD_REQUEST]
#[body = "Request body does not contain valid UTF-8"]
pub struct InvalidUtf8(Error);
}
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "Error handling HTTP request"]
pub struct Http(Error);
}
define_rejection! {
#[status = BAD_REQUEST]
#[body = "Error parsing headers"]
pub struct HeadersParse(Error);
}
define_rejection! {
#[status = BAD_REQUEST]
#[body = "Expected `Content-Type: application/json`"]
pub struct MissingJsonContentType;
}
define_rejection! {
#[status = BAD_REQUEST]
#[body = "Failed to parse request MIME type"]
pub struct MimeParsingFailed;
}
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "Extensions taken by other extractor"]
pub struct ExtensionsAlreadyExtracted;
}
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "Missing request extension"]
pub struct MissingExtension(Error);
}
composite_rejection! {
pub enum ContentTypeRejection {
MissingJsonContentType,
MimeParsingFailed,
}
}
composite_rejection! {
pub enum ExtensionRejection {
MissingExtension,
ExtensionsAlreadyExtracted,
}
}
composite_rejection! {
pub enum SmithyRejection {
Serialize,
Deserialize,
InvalidUtf8,
Http,
HeadersParse,
ContentTypeRejection,
BodyAlreadyExtracted,
HeadersAlreadyExtracted,
}
}
impl From<aws_smithy_json::deserialize::Error> for SmithyRejection {
fn from(err: aws_smithy_json::deserialize::Error) -> Self {
SmithyRejection::Deserialize(Deserialize::from_err(err))
}
}
impl From<aws_smithy_http::operation::BuildError> for SmithyRejection {
fn from(err: aws_smithy_http::operation::BuildError) -> Self {
SmithyRejection::Deserialize(Deserialize::from_err(err))
}
}
impl From<std::num::ParseIntError> for SmithyRejection {
fn from(err: std::num::ParseIntError) -> Self {
SmithyRejection::Deserialize(Deserialize::from_err(err))
}
}
impl From<aws_smithy_http::operation::SerializationError> for SmithyRejection {
fn from(err: aws_smithy_http::operation::SerializationError) -> Self {
SmithyRejection::Serialize(Serialize::from_err(err))
}
}
impl From<std::str::Utf8Error> for SmithyRejection {
fn from(err: std::str::Utf8Error) -> Self {
SmithyRejection::InvalidUtf8(InvalidUtf8::from_err(err))
}
}
impl From<http::Error> for SmithyRejection {
fn from(err: http::Error) -> Self {
SmithyRejection::Http(Http::from_err(err))
}
}
impl From<hyper::Error> for SmithyRejection {
fn from(err: hyper::Error) -> Self {
SmithyRejection::Http(Http::from_err(err))
}
}
impl From<aws_smithy_http::header::ParseError> for SmithyRejection {
fn from(err: aws_smithy_http::header::ParseError) -> Self {
SmithyRejection::HeadersParse(HeadersParse::from_err(err))
}
}