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:
parent
467725641f
commit
07d87c9c91
|
@ -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) {
|
||||
|
|
|
@ -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]]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue