1use poem::{error::ResponseError, http::StatusCode};
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8#[error("failed to parse parameter `{name}`: {reason}")]
9pub struct ParseParamError {
10 pub name: &'static str,
12
13 pub reason: String,
15}
16
17impl ResponseError for ParseParamError {
18 fn status(&self) -> StatusCode {
19 StatusCode::BAD_REQUEST
20 }
21}
22
23#[derive(Debug, Error)]
25#[error("failed to parse path `{name}`: {reason}")]
26pub struct ParsePathError {
27 pub name: &'static str,
29
30 pub reason: String,
32}
33
34impl ResponseError for ParsePathError {
35 fn status(&self) -> StatusCode {
36 StatusCode::BAD_REQUEST
37 }
38}
39
40#[derive(Debug, Error)]
42#[error("parse request payload error: {reason}")]
43pub struct ParseRequestPayloadError {
44 pub reason: String,
46}
47
48impl ResponseError for ParseRequestPayloadError {
49 fn status(&self) -> StatusCode {
50 StatusCode::BAD_REQUEST
51 }
52}
53
54#[derive(Debug, Error)]
56#[error("parse multipart error: {reason}")]
57pub struct ParseMultipartError {
58 pub reason: String,
60}
61
62impl ResponseError for ParseMultipartError {
63 fn status(&self) -> StatusCode {
64 StatusCode::BAD_REQUEST
65 }
66}
67
68#[derive(Debug, Error)]
70pub enum ContentTypeError {
71 #[error("the `Content-Type` requested by the client is not supported: {content_type}")]
73 NotSupported {
74 content_type: String,
76 },
77
78 #[error("the client request does not include the `Content-Type` header")]
80 ExpectContentType,
81}
82
83impl ResponseError for ContentTypeError {
84 fn status(&self) -> StatusCode {
85 StatusCode::UNSUPPORTED_MEDIA_TYPE
86 }
87}
88
89#[derive(Debug, Error)]
91#[error("authorization error")]
92pub struct AuthorizationError;
93
94impl ResponseError for AuthorizationError {
95 fn status(&self) -> StatusCode {
96 StatusCode::UNAUTHORIZED
97 }
98}