handle internal server error

This commit is contained in:
xfy
2024-04-28 10:51:24 +08:00
parent 0675182407
commit 24bd211cab
2 changed files with 15 additions and 4 deletions

View File

@ -47,7 +47,7 @@ pub async fn handle_file(path: &str) -> Result<CandyBody<Bytes>> {
let cache = get_cache().read()?;
match cache.get(path) {
Some(time) => {
dbg!(time, last_modified);
// dbg!(time, last_modified);
}
None => {
drop(cache);
@ -79,3 +79,15 @@ pub fn not_found() -> Response<CandyBody<Bytes>> {
.body(Full::new(NOT_FOUND.into()).map_err(|e| match e {}).boxed())
.unwrap()
}
static INTERNAL_SERVER_ERROR: &[u8] = b"Internal Server Error";
pub fn internal_server_error() -> Response<CandyBody<Bytes>> {
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(
Full::new(INTERNAL_SERVER_ERROR.into())
.map_err(|e| match e {})
.boxed(),
)
.unwrap()
}

View File

@ -6,7 +6,7 @@ use std::{
use crate::{
error::{Error, Result},
http::{handle_file, not_found, CandyBody},
http::{handle_file, internal_server_error, not_found, CandyBody},
utils::{find_route, parse_assets_path},
};
@ -54,8 +54,7 @@ impl SettingHost {
warn!("{err}");
not_found()
}
// TODO: handle other error
_ => todo!(),
_ => internal_server_error(),
};
let end_time = (Instant::now() - start_time).as_micros() as f32;
let end_time = end_time / 1000_f32;