diff --git a/autoendpoint/src/error.rs b/autoendpoint/src/error.rs index 358b0a1b..25ca9fb2 100644 --- a/autoendpoint/src/error.rs +++ b/autoendpoint/src/error.rs @@ -108,11 +108,11 @@ pub enum ApiErrorKind { #[error("Invalid message ID")] InvalidMessageId, - #[error("{0}")] - Internal(String), - #[error("Invalid Authentication")] InvalidAuthentication, + + #[error("ERROR:Success")] + LogCheck, } impl ApiErrorKind { @@ -138,12 +138,13 @@ impl ApiErrorKind { ApiErrorKind::NoUser | ApiErrorKind::NoSubscription => StatusCode::GONE, + ApiErrorKind::LogCheck => StatusCode::IM_A_TEAPOT, + ApiErrorKind::Io(_) | ApiErrorKind::Metrics(_) | ApiErrorKind::Database(_) | ApiErrorKind::EndpointUrl(_) - | ApiErrorKind::RegistrationSecretHash(_) - | ApiErrorKind::Internal(_) => StatusCode::INTERNAL_SERVER_ERROR, + | ApiErrorKind::RegistrationSecretHash(_) => StatusCode::INTERNAL_SERVER_ERROR, } } @@ -178,7 +179,7 @@ impl ApiErrorKind { ApiErrorKind::NoTTL => Some(111), - ApiErrorKind::Internal(_) => Some(999), + ApiErrorKind::LogCheck => Some(999), ApiErrorKind::Io(_) | ApiErrorKind::Metrics(_) @@ -228,23 +229,6 @@ where } } -impl From> for ApiError { - fn from(inner: actix_web::error::BlockingError) -> Self { - match inner { - actix_web::error::BlockingError::Error(e) => e, - actix_web::error::BlockingError::Canceled => { - ApiErrorKind::Internal("Db threadpool operation canceled".to_owned()).into() - } - } - } -} - -impl From for HttpResponse { - fn from(inner: ApiError) -> Self { - ResponseError::error_response(&inner) - } -} - impl ResponseError for ApiError { fn status_code(&self) -> StatusCode { self.kind.status() diff --git a/autoendpoint/src/routes/health.rs b/autoendpoint/src/routes/health.rs index 830704f8..5492988c 100644 --- a/autoendpoint/src/routes/health.rs +++ b/autoendpoint/src/routes/health.rs @@ -1,10 +1,13 @@ //! Health and Dockerflow routes use crate::db::error::DbResult; +use crate::error::{ApiErrorKind, ApiResult}; use crate::server::ServerState; use actix_web::web::{Data, Json}; use actix_web::HttpResponse; +use reqwest::StatusCode; use serde_json::json; +use std::thread; /// Handle the `/health` and `/__heartbeat__` routes pub async fn health_route(state: Data) -> Json { @@ -58,3 +61,18 @@ pub fn version_route() -> HttpResponse { .content_type("application/json") .body(include_str!("../../../version.json")) } + +/// Handle the `/v1/err` route +pub async fn log_check() -> ApiResult { + error!( + "Test Critical Message"; + "status_code" => StatusCode::IM_A_TEAPOT.as_u16(), + "errno" => 999, + ); + + thread::spawn(|| { + panic!("LogCheck"); + }); + + Err(ApiErrorKind::LogCheck.into()) +} diff --git a/autoendpoint/src/server.rs b/autoendpoint/src/server.rs index 3fef2d10..47e264dc 100644 --- a/autoendpoint/src/server.rs +++ b/autoendpoint/src/server.rs @@ -7,7 +7,9 @@ use crate::middleware::sentry::sentry_middleware; use crate::routers::adm::router::AdmRouter; use crate::routers::apns::router::ApnsRouter; use crate::routers::fcm::router::FcmRouter; -use crate::routes::health::{health_route, lb_heartbeat_route, status_route, version_route}; +use crate::routes::health::{ + health_route, lb_heartbeat_route, log_check, status_route, version_route, +}; use crate::routes::registration::{ get_channels_route, new_channel_route, register_uaid_route, unregister_channel_route, unregister_user_route, update_token_route, @@ -131,6 +133,7 @@ impl Server { // Health checks .service(web::resource("/status").route(web::get().to(status_route))) .service(web::resource("/health").route(web::get().to(health_route))) + .service(web::resource("/v1/err").route(web::get().to(log_check))) // Dockerflow .service(web::resource("/__heartbeat__").route(web::get().to(health_route))) .service(web::resource("/__lbheartbeat__").route(web::get().to(lb_heartbeat_route)))