From 9c92603bbe96c1bb54db5247ba73e7ea447845c1 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 3 Jun 2020 15:21:36 -0700 Subject: [PATCH] Expect defailed error message from the server when rejecting a move The server was recently augmented to not simply say 'false' for an illegal move, but to instead say something like: {"legal": false, "message": "Square already occupied"} So we plumb the server-provided message out to the user in the case of any illegal move. --- tictactoe/tictactoe.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tictactoe/tictactoe.jsx b/tictactoe/tictactoe.jsx index 5d1845d..61a828e 100644 --- a/tictactoe/tictactoe.jsx +++ b/tictactoe/tictactoe.jsx @@ -139,9 +139,9 @@ class Game extends React.Component { async handleClick(i) { const response = await this.sendMove(i); if (response.status == 200) { - const legal = await response.json(); - if (! legal) - add_message("danger", `Illegal move.`); + const result = await response.json(); + if (! result.legal) + add_message("danger", result.message); } else { add_message("danger", `Error occurred sending move`); } -- 2.43.0