From: Ian Jackson Date: Fri, 19 Mar 2021 01:13:50 +0000 (+0000) Subject: clock: Use BadPieceStateForOperation X-Git-Tag: otter-0.5.0~645 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=693521c9426a6f9c5cfb69df63b1fa7f32b02b88;p=otter.git clock: Use BadPieceStateForOperation Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index 8de37284..13ee5246 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -77,7 +77,8 @@ impl From<&OnlineErrorResponse> for rocket::http::Status { NoClient | NoPlayer(_) | GameBeingDestroyed => Status::NotFound, OE::PieceHeld | OE::PieceGone | - OE::OverlappingOccultation | OE::Occultation + OE::OverlappingOccultation | OE::Occultation | + OE::BadPieceStateForOperation => Status::Conflict, InvalidZCoord | BadOperation | BadJSON(_) => Status::BadRequest, diff --git a/src/clock.rs b/src/clock.rs index 96bf5c78..228dd351 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -414,7 +414,7 @@ impl PieceTrait for Clock { }, "reset" => { if state.current.is_some() { - throw!(OE::BadOperation); + throw!(OE::BadPieceStateForOperation); } for ust in &mut state.users { ust.remaining = self.spec.initial_time(); @@ -423,19 +423,19 @@ impl PieceTrait for Clock { "claim-x" | "claim-y" => { let user = get_user(); if let Some(_gpl) = gs.players.get(state.users[user].player) { - throw!(OE::BadOperation); + throw!(OE::BadPieceStateForOperation); } state.users[user].player = player; }, "unclaim-x" | "unclaim-y" => { let user = get_user(); if state.users[user].player != player { - throw!(OE::BadOperation); + throw!(OE::BadPieceStateForOperation); } state.users[user].player = default(); }, _ => { - throw!(OE::BadOperation); + throw!(OE::BadPieceStateForOperation); } } diff --git a/src/error.rs b/src/error.rs index b410fd86..03a947d4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -28,6 +28,8 @@ pub enum OnlineError { OverlappingOccultation, #[error("piece is occulting, or occulted")] Occultation, + #[error("UI operation not valid in the curret piece state")] + BadPieceStateForOperation, } from_instance_lock_error!{OnlineError}