chiark / gitweb /
clock: Use BadPieceStateForOperation
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Mar 2021 01:13:50 +0000 (01:13 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 20:12:41 +0000 (20:12 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/clock.rs
src/error.rs

index 8de3728450501ad98adf8d0ff308875a16aab44c..13ee5246969f09bcea121db9d1e3eff42ccad3ac 100644 (file)
@@ -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,
index 96bf5c78cf110b43f1fd7883ab93b078b1672874..228dd35134b406137f5388b4792ff7bcf35b4920 100644 (file)
@@ -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);
       }
     }
 
index b410fd862e4ea8861a62ee5b4ad4c3d4b3d26d25..03a947d4f8aaf22411a4eafa1d0954117928ed3c 100644 (file)
@@ -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}