From a6a847fc8e983e97b7c97c7047d69aec62221800 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 29 Aug 2020 14:00:00 +0100 Subject: [PATCH] handle piece api errors --- src/api.rs | 6 ++++++ src/error.rs | 2 ++ src/http.rs | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api.rs b/src/api.rs index 70deb90f..50ef5f7a 100644 --- a/src/api.rs +++ b/src/api.rs @@ -93,6 +93,12 @@ fn api_piece_op(form : Json>) 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)), diff --git a/src/error.rs b/src/error.rs index addd35bf..f7d562c5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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:?}")] diff --git a/src/http.rs b/src/http.rs index 15065f01..baaad11f 100644 --- a/src/http.rs +++ b/src/http.rs @@ -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); -- 2.30.2