use poem::{error::ResponseError, http::StatusCode};
use thiserror::Error;
#[derive(Debug, Error)]
#[error("failed to parse parameter `{name}`: {reason}")]
pub struct ParseParamError {
pub name: &'static str,
pub reason: String,
}
impl ResponseError for ParseParamError {
fn status(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}
#[derive(Debug, Error)]
#[error("failed to parse path `{name}`: {reason}")]
pub struct ParsePathError {
pub name: &'static str,
pub reason: String,
}
impl ResponseError for ParsePathError {
fn status(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}
#[derive(Debug, Error)]
#[error("parse request payload error: {reason}")]
pub struct ParseRequestPayloadError {
pub reason: String,
}
impl ResponseError for ParseRequestPayloadError {
fn status(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}
#[derive(Debug, Error)]
#[error("parse multipart error: {reason}")]
pub struct ParseMultipartError {
pub reason: String,
}
impl ResponseError for ParseMultipartError {
fn status(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}
#[derive(Debug, Error)]
pub enum ContentTypeError {
#[error("the `Content-Type` requested by the client is not supported: {content_type}")]
NotSupported {
content_type: String,
},
#[error("the client request does not include the `Content-Type` header")]
ExpectContentType,
}
impl ResponseError for ContentTypeError {
fn status(&self) -> StatusCode {
StatusCode::UNSUPPORTED_MEDIA_TYPE
}
}
#[derive(Debug, Error)]
#[error("authorization error")]
pub struct AuthorizationError;
impl ResponseError for AuthorizationError {
fn status(&self) -> StatusCode {
StatusCode::UNAUTHORIZED
}
}