Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@ struct PathStep {
to: WebStar,
}
#[derive(Debug, Serialize)]
enum PathResult {
Found(Vec<PathStep>),
Timeout,
NotFound,
}
#[derive(Debug, Serialize)]
struct PathReturn {
version: u32,
data: Vec<PathStep>,
data: PathResult,
}

#[get("/path?<start>&<end>&<jump>&<optimize>&<use_smart_gates>")]
Expand Down Expand Up @@ -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,
})),
}
}

Expand Down