From: Ian Jackson Date: Sat, 29 Aug 2020 13:00:00 +0000 (+0100) Subject: handle piece api errors X-Git-Tag: otter-0.2.0~1041 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a6a847fc8e983e97b7c97c7047d69aec62221800;p=otter.git handle piece api errors --- 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);