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.
This commit is contained in:
Gavin Lambert 2013-06-10 23:16:50 +12:00
parent 467725641f
commit 07d87c9c91
2 changed files with 17 additions and 1 deletions

View File

@ -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) { cah.ajax.SuccessHandlers[cah.$.AjaxOperation.LEAVE_GAME] = function(data, req) {
var game = cah.currentGames[req[cah.$.AjaxRequest.GAME_ID]]; var game = cah.currentGames[req[cah.$.AjaxRequest.GAME_ID]];
if (game) { if (game) {
@ -139,7 +148,14 @@ cah.ajax.SuccessHandlers[cah.$.AjaxOperation.LEAVE_GAME] = function(data, req) {
} }
cah.GameList.instance.show(); cah.GameList.instance.show();
cah.GameList.instance.update(); 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) { cah.ajax.SuccessHandlers[cah.$.AjaxOperation.START_GAME] = function(data, req) {

View File

@ -123,7 +123,7 @@ cah.Ajax.prototype.done = function(data) {
// "you don't have that card" etc. // "you don't have that card" etc.
var req = this.pendingRequests_[data[cah.$.AjaxResponse.SERIAL]]; var req = this.pendingRequests_[data[cah.$.AjaxResponse.SERIAL]];
if (req && cah.ajax.ErrorHandlers[req.getOp()]) { if (req && cah.ajax.ErrorHandlers[req.getOp()]) {
cah.ajax.ErrorHandlers[req.getOp()](data); cah.ajax.ErrorHandlers[req.getOp()](data, req.data);
} else { } else {
cah.log.error(cah.$.ErrorCode_msg[data[cah.$.AjaxResponse.ERROR_CODE]]); cah.log.error(cah.$.ErrorCode_msg[data[cah.$.AjaxResponse.ERROR_CODE]]);
} }