You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.7 KiB
51 lines
1.7 KiB
2 years ago
|
use actix_web::HttpResponse;
|
||
|
|
||
|
pub enum Error {
|
||
|
InvalidOrigin,
|
||
|
InvalidBody,
|
||
|
InvalidUrl,
|
||
|
InvalidFields,
|
||
|
InvalidContentId,
|
||
|
InvalidParent,
|
||
|
EmailRequired,
|
||
|
NameRequired,
|
||
|
DatabaseAccessError,
|
||
|
DatabaseInternalError,
|
||
|
SanitizationError,
|
||
|
PageFetchError,
|
||
|
}
|
||
|
|
||
|
impl Error {
|
||
|
pub fn to_http_response(&self) -> HttpResponse {
|
||
|
match self {
|
||
|
Self::InvalidOrigin
|
||
|
| Self::InvalidBody
|
||
|
| Self::InvalidUrl
|
||
|
| Self::InvalidFields
|
||
|
| Self::InvalidContentId
|
||
|
| Self::InvalidParent
|
||
|
| Self::EmailRequired
|
||
|
| Self::NameRequired => HttpResponse::BadRequest(),
|
||
|
Self::DatabaseAccessError
|
||
|
| Self::DatabaseInternalError
|
||
|
| Self::SanitizationError
|
||
|
| Self::PageFetchError => HttpResponse::InternalServerError(),
|
||
|
}
|
||
|
.reason(match self {
|
||
|
Self::InvalidOrigin => "invalid request origin",
|
||
|
Self::InvalidBody => "invalid request body",
|
||
|
Self::InvalidUrl => "invalid request url",
|
||
|
Self::InvalidFields => "invalid request field",
|
||
|
Self::InvalidContentId => "invalid request content id",
|
||
|
Self::InvalidParent => "invalid comment parent",
|
||
|
Self::EmailRequired => "comment email required",
|
||
|
Self::NameRequired => "comment name required",
|
||
|
Self::DatabaseAccessError => "database access error",
|
||
|
Self::DatabaseInternalError => "database internal error",
|
||
|
Self::SanitizationError => "comment sanitization error",
|
||
|
Self::PageFetchError => "page fetch error",
|
||
|
})
|
||
|
.finish()
|
||
|
}
|
||
|
}
|