parent
6de079b279
commit
98dc007fa4
@ -0,0 +1,50 @@
|
||||
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()
|
||||
}
|
||||
}
|
Loading…
Reference in new issue