chiark / gitweb /
handle piece api errors
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Aug 2020 13:00:00 +0000 (14:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Aug 2020 13:00:00 +0000 (14:00 +0100)
src/api.rs
src/error.rs
src/http.rs

index 70deb90f6dd65058d124d49f35daa8f747cb2895..50ef5f7a42113f29f1fef13db2b98b1743431642 100644 (file)
@@ -93,6 +93,12 @@ fn api_piece_op<O: ApiPieceOp>(form : Json<ApiPiece<O>>)
       let err : GameError = err;
       if let GameError::InternalErrorSVG(svg) = err { throw!(svg) }
       eprintln!("API {:?} => {:?}", &form, &err);
+      // Restating the state of this piece (with a new generation)
+      // will forcibly synchronise the client which made the failing
+      // request.
+      let mut buf = PrepareUpdatesBuffer::new(g, None, None);
+      buf.piece_update(piece, PieceUpdateOp::Modify(()), &lens);
+      throw!(err);
     },
     Ok((update, logents)) => {
       let mut buf = PrepareUpdatesBuffer::new(g, Some((client, form.cseq)),
index addd35bffb47ae6879908421b677612f574386fd..f7d562c58256a464464156b244bc14321c8e6709 100644 (file)
@@ -21,6 +21,8 @@ pub enum OnlineError {
   NoClient,
   #[error("player not part of game (removed?)")]
   NoPlayer,
+  #[error("game operation error")]
+  GameError(#[from] GameError),
   #[error("invalid Z coordinate")]
   InvalidZCoord,
   #[error("JSON~ serialisation error: {0:?}")]
index 15065f01a21400d851cfe54a9a7d4ee2a44b7366..baaad11ffc8e374a169eabef8f456590815a3911 100644 (file)
@@ -18,7 +18,7 @@ impl<'r> Responder<'r> for OnlineError {
         | ServerFailure(_)
         => Status::InternalServerError,
       NoClient | NoPlayer | GameBeingDestroyed => Status::NotFound,
-      InvalidZCoord => Status::BadRequest,
+      InvalidZCoord | OnlineError::GameError(_) => Status::BadRequest,
     };
     let mut resp = Responder::respond_to(msg,req).unwrap();
     resp.set_status(status);