From f2b16d4087d3e8eccfa8c6bb1cb06bf14844cf3f Mon Sep 17 00:00:00 2001 From: curly Date: Mon, 13 Feb 2023 15:22:11 -0700 Subject: error handling --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01dd077..f211f99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1143,7 +1143,7 @@ dependencies = [ [[package]] name = "rocket_test" -version = "0.2.0" +version = "0.2.1" dependencies = [ "chrono", "rocket", diff --git a/Cargo.toml b/Cargo.toml index 6ba4d6c..515f4ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rocket_test" -version = "0.2.0" +version = "0.2.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 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