From 693521c9426a6f9c5cfb69df63b1fa7f32b02b88 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 19 Mar 2021 01:13:50 +0000 Subject: [PATCH] clock: Use BadPieceStateForOperation Signed-off-by: Ian Jackson --- daemon/api.rs | 3 ++- src/clock.rs | 8 ++++---- src/error.rs | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) 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} -- 2.30.2