From 07d87c9c912c17f4f990e006db67b426800fde33 Mon Sep 17 00:00:00 2001 From: Gavin Lambert Date: Mon, 10 Jun 2013 23:16:50 +1200 Subject: [PATCH] Add some error handlers for leaving games. Trying to leave an invalid game always succeeds. Trying to get game info about an invalid game (that you think you're still in) makes you leave it. --- WebContent/js/cah.ajax.handlers.js | 16 ++++++++++++++++ WebContent/js/cah.ajax.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/WebContent/js/cah.ajax.handlers.js b/WebContent/js/cah.ajax.handlers.js index 48ecd53..ad9b61e 100644 --- a/WebContent/js/cah.ajax.handlers.js +++ b/WebContent/js/cah.ajax.handlers.js @@ -131,6 +131,15 @@ cah.ajax.SuccessHandlers[cah.$.AjaxOperation.GET_GAME_INFO] = function(data, req } }; +cah.ajax.ErrorHandlers[cah.$.AjaxOperation.GET_GAME_INFO] = function(data, req) { + if (data[cah.$.AjaxResponse.ERROR_CODE] == cah.$.ErrorCode.INVALID_GAME) { + cah.log.error("The game has been removed. Returning to the lobby."); + cah.ajax.SuccessHandlers[cah.$.AjaxOperation.LEAVE_GAME](data, req); + } else { + cah.log.error(cah.$.ErrorCode_msg[data[cah.$.AjaxResponse.ERROR_CODE]]); + } +}; + cah.ajax.SuccessHandlers[cah.$.AjaxOperation.LEAVE_GAME] = function(data, req) { var game = cah.currentGames[req[cah.$.AjaxRequest.GAME_ID]]; if (game) { @@ -139,7 +148,14 @@ cah.ajax.SuccessHandlers[cah.$.AjaxOperation.LEAVE_GAME] = function(data, req) { } cah.GameList.instance.show(); cah.GameList.instance.update(); +}; +cah.ajax.ErrorHandlers[cah.$.AjaxOperation.LEAVE_GAME] = function(data, req) { + if (data[cah.$.AjaxResponse.ERROR_CODE] == cah.$.ErrorCode.INVALID_GAME) { + cah.ajax.SuccessHandlers[cah.$.AjaxOperation.LEAVE_GAME](data, req); + } else { + cah.log.error(cah.$.ErrorCode_msg[data[cah.$.AjaxResponse.ERROR_CODE]]); + } }; cah.ajax.SuccessHandlers[cah.$.AjaxOperation.START_GAME] = function(data, req) { diff --git a/WebContent/js/cah.ajax.js b/WebContent/js/cah.ajax.js index 7e64df5..a8889ff 100644 --- a/WebContent/js/cah.ajax.js +++ b/WebContent/js/cah.ajax.js @@ -123,7 +123,7 @@ cah.Ajax.prototype.done = function(data) { // "you don't have that card" etc. var req = this.pendingRequests_[data[cah.$.AjaxResponse.SERIAL]]; if (req && cah.ajax.ErrorHandlers[req.getOp()]) { - cah.ajax.ErrorHandlers[req.getOp()](data); + cah.ajax.ErrorHandlers[req.getOp()](data, req.data); } else { cah.log.error(cah.$.ErrorCode_msg[data[cah.$.AjaxResponse.ERROR_CODE]]); }