From f2b16d4087d3e8eccfa8c6bb1cb06bf14844cf3f Mon Sep 17 00:00:00 2001 From: curly Date: Mon, 13 Feb 2023 15:22:11 -0700 Subject: error handling --- src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 3d5398b..1955963 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,8 +26,12 @@ fn get_message(id: usize, db: &State) -> Json/")] fn get_message_id_list(id_start: u64, id_end: u64, db: &State) -> Json, &'static str>> { - if id_end - id_start > 25 { + let delta = id_end as i128 - id_start as i128; + + if delta > 25 { return Json(Response(Err("Request limit is 25"))) + } else if delta < 0 { + return Json(Response(Err("Request range is less than 0"))) } let lock = db.sdb.lock().unwrap(); @@ -41,8 +45,12 @@ fn get_message_id_list(id_start: u64, id_end: u64, db: &State) -> Json } #[get("/get_message_list//")] fn get_message_list(id_start: u64, id_end: u64, db: &State) -> Json, &'static str>> { - if id_end - id_start > 25 { + let delta = id_end as i128 - id_start as i128; + + if delta > 25 { return Json(Response(Err("Request limit is 25"))) + } else if delta < 0 { + return Json(Response(Err("Request range is less than 0"))) } let lock = db.sdb.lock().unwrap(); -- cgit v1.2.3