use actix_web::HttpResponse;
use lazy_static::lazy_static;
use prometheus::IntCounter;
lazy_static! {
static ref NUM_404_REQUESTS: IntCounter =
register_int_counter!("throttle_num_404", "Number of Get requests to unknown resource.")
.expect("Error registering num_404 prometheus metric");
}
const NOT_FOUND_PAGE: &str = include_str!("404.html");
pub async fn not_found() -> HttpResponse {
NUM_404_REQUESTS.inc();
HttpResponse::NotFound()
.content_type("text/html")
.body(NOT_FOUND_PAGE)
}
pub fn initialize_metrics() {
lazy_static::initialize(&NUM_404_REQUESTS);
}
#[cfg(test)]
mod tests {
use super::*;
use actix_web::http;
#[actix_rt::test]
async fn status_code() {
let resp = not_found().await;
assert_eq!(resp.status(), http::StatusCode::NOT_FOUND);
}
}