diff --git a/src/errors.rs b/src/errors.rs index 1c7088f..fbd9dd0 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -187,70 +187,70 @@ impl From for ServiceError { #[cfg(not(tarpaulin_include))] pub type ServiceResult = std::result::Result; -//#[derive(Debug, Display, PartialEq, Error)] -//#[cfg(not(tarpaulin_include))] -//pub enum PageError { -// #[display(fmt = "Something weng wrong: Internal server error")] -// InternalServerError, -// -// #[display(fmt = "{}", _0)] -// ServiceError(ServiceError), -//} -// -//#[cfg(not(tarpaulin_include))] -//impl From for PageError { -// #[cfg(not(tarpaulin_include))] -// fn from(_: sqlx::Error) -> Self { -// PageError::InternalServerError -// } -//} -// -//#[cfg(not(tarpaulin_include))] -//impl From for PageError { -// #[cfg(not(tarpaulin_include))] -// fn from(e: ServiceError) -> Self { -// PageError::ServiceError(e) -// } -//} -// -//impl ResponseError for PageError { -// fn error_response(&self) -> HttpResponse { -// use crate::PAGES; -// match self.status_code() { -// StatusCode::INTERNAL_SERVER_ERROR => HttpResponse::Found() -// .append_header((header::LOCATION, PAGES.errors.internal_server_error)) -// .finish(), -// _ => HttpResponse::Found() -// .append_header((header::LOCATION, PAGES.errors.unknown_error)) -// .finish(), -// } -// } -// -// #[cfg(not(tarpaulin_include))] -// fn status_code(&self) -> StatusCode { -// match self { -// PageError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR, -// PageError::ServiceError(e) => e.status_code(), -// } -// } -//} -// -//#[cfg(not(tarpaulin_include))] -//pub type PageResult = std::result::Result; -// -//#[cfg(test)] -//mod tests { -// use super::*; -// use crate::PAGES; -// -// #[test] -// fn error_works() { -// let resp: HttpResponse = PageError::InternalServerError.error_response(); -// assert_eq!(resp.status(), StatusCode::FOUND); -// let headers = resp.headers(); -// assert_eq!( -// headers.get(header::LOCATION).unwrap(), -// PAGES.errors.internal_server_error -// ); -// } -//} +#[derive(Debug, Display, PartialEq, Error)] +#[cfg(not(tarpaulin_include))] +pub enum PageError { + #[display(fmt = "Something weng wrong: Internal server error")] + InternalServerError, + + #[display(fmt = "{}", _0)] + ServiceError(ServiceError), +} + +#[cfg(not(tarpaulin_include))] +impl From for PageError { + #[cfg(not(tarpaulin_include))] + fn from(_: sqlx::Error) -> Self { + PageError::InternalServerError + } +} + +#[cfg(not(tarpaulin_include))] +impl From for PageError { + #[cfg(not(tarpaulin_include))] + fn from(e: ServiceError) -> Self { + PageError::ServiceError(e) + } +} + +impl ResponseError for PageError { + fn error_response(&self) -> HttpResponse { + use crate::PAGES; + match self.status_code() { + StatusCode::INTERNAL_SERVER_ERROR => HttpResponse::Found() + .append_header((header::LOCATION, PAGES.errors.internal_server_error)) + .finish(), + _ => HttpResponse::Found() + .append_header((header::LOCATION, PAGES.errors.unknown_error)) + .finish(), + } + } + + #[cfg(not(tarpaulin_include))] + fn status_code(&self) -> StatusCode { + match self { + PageError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR, + PageError::ServiceError(e) => e.status_code(), + } + } +} + +#[cfg(not(tarpaulin_include))] +pub type PageResult = std::result::Result; + +#[cfg(test)] +mod tests { + use super::*; + use crate::PAGES; + + #[test] + fn error_works() { + let resp: HttpResponse = PageError::InternalServerError.error_response(); + assert_eq!(resp.status(), StatusCode::FOUND); + let headers = resp.headers(); + assert_eq!( + headers.get(header::LOCATION).unwrap(), + PAGES.errors.internal_server_error + ); + } +}