From 48af4e73f92826fc2f83c854b5f1a585027205ac Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 21 Apr 2025 18:53:28 +0100 Subject: [PATCH] have /calc/path return an enum --- backend/web.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/backend/web.rs b/backend/web.rs index f9f4ca5..c394704 100644 --- a/backend/web.rs +++ b/backend/web.rs @@ -142,9 +142,15 @@ struct PathStep { to: WebStar, } #[derive(Debug, Serialize)] +enum PathResult { + Found(Vec), + Timeout, + NotFound, +} +#[derive(Debug, Serialize)] struct PathReturn { version: u32, - data: Vec, + data: PathResult, } #[get("/path?&&&&")] @@ -203,17 +209,18 @@ fn calc_path( last_id = conn.target; } Ok(Json(PathReturn { - version: 2, - data: result, + version: 3, + data: PathResult::Found(result), })) } - eftb::calc::path::PathResult::NotFound => { - Err(CustomError(Status::NotFound, format!("No path found"))) - } - eftb::calc::path::PathResult::Timeout => Err(CustomError( - Status::InternalServerError, - format!("Path calculation timed out"), - )), + eftb::calc::path::PathResult::Timeout => Ok(Json(PathReturn { + version: 3, + data: PathResult::Timeout, + })), + eftb::calc::path::PathResult::NotFound => Ok(Json(PathReturn { + version: 3, + data: PathResult::NotFound, + })), } }