From edfc33800fb831478f904ce8426d030ab2ed4efe Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Fri, 4 Jan 2013 03:40:04 +0000 Subject: [PATCH] Improving error handling in Game and Game Hall screens. --- .../lotro/game/LotroGameMediator.java | 4 ++ .../src/main/webapp/js/gemp-014/gameUi.js | 71 ++++++++++++++++--- .../src/main/webapp/js/gemp-014/hallUi.js | 2 +- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java index 8e09e6d0a..51b249803 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java @@ -321,7 +321,11 @@ public class LotroGameMediator { } } } + } else { + throw new WebApplicationException(Response.Status.CONFLICT); } + } else { + throw new WebApplicationException(Response.Status.GONE); } } finally { _writeLock.unlock(); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/gameUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/gameUi.js index f0a9105ef..4ee9c15d2 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/gameUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/gameUi.js @@ -851,14 +851,6 @@ var GempLotrGameUI = Class.extend({ } }, - startGameSession:function () { - var that = this; - this.communication.startGameSession( - function (xml) { - that.processXml(xml, false); - }); - }, - startReplaySession:function (replayId) { var that = this; this.communication.getReplay(replayId, @@ -867,13 +859,21 @@ var GempLotrGameUI = Class.extend({ }); }, + startGameSession:function () { + var that = this; + this.communication.startGameSession( + function (xml) { + that.processXml(xml, false); + }, this.gameErrorMap()); + }, + updateGameState:function () { var that = this; this.communication.updateGameState( this.channelNumber, function (xml) { that.processXml(xml, true); - }); + }, this.gameErrorMap()); }, decisionFunction:function (decisionId, result) { @@ -882,9 +882,60 @@ var GempLotrGameUI = Class.extend({ this.channelNumber, function (xml) { that.processXml(xml, true); - }); + }, this.gameErrorMap()); }, + gameErrorMap:function() { + var that = this; + return { + "0": function() { + that.showErrorDialog("Server connection error", "Unable to connect to server. Either server is down or there is a problem with your internet connection.", true, false, false); + }, + "401":function() { + that.showErrorDialog("Authentication error", "You are not logged in", false, true, false); + }, + "403":function() { + that.showErrorDialog("Game access forbidden", "This game is private and does not allow spectators.", false, false, true); + }, + "409":function() { + that.showErrorDialog("Concurrent access error", "You are observing this Game Hall from another browser or window. Close this window or if you wish to observe it here, click \"Refresh page\".", true, false, false); + }, + "410":function() { + that.showErrorDialog("Inactivity error", "You were inactive for too long and have been removed from observing this game. If you wish to start again, click \"Refresh page\".", true, false, false); + } + }; + }, + + showErrorDialog:function(title, text, reloadButton, mainPageButton, gameHallButton) { + var buttons = {}; + if (reloadButton) { + buttons["Refresh page"] = + function () { + location.reload(true); + }; + } + if (mainPageButton) { + buttons["Go to main page"] = + function() { + location.href = "/gemp-lotr/"; + }; + } + if (gameHallButton) { + buttons["Go to Game Hall"] = + function() { + location.href = "/game-lotr/hall.html"; + }; + } + + var dialog = $("
").dialog({ + title: title, + resizable: false, + height: 160, + modal: true, + buttons: buttons + }).text(text); + }, + getCardModifiersFunction:function (cardId, func) { var that = this; this.communication.getGameCardModifiers(cardId, diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js index 92db320c9..714abe21b 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js @@ -300,7 +300,7 @@ var GempLotrHallUI = Class.extend({ that.showErrorDialog("Concurrent access error", "You are accessing Game Hall from another browser or window. Close this window or if you wish to access Game Hall from here, click \"Refresh page\".", true, false); }, "410":function() { - that.showErrorDialog("Inactivity error", "You were inactive for too long and you have been removed from the Game Hall. If you wish to re-enter, clich \"Refresh page\".", true, false); + that.showErrorDialog("Inactivity error", "You were inactive for too long and have been removed from the Game Hall. If you wish to re-enter, click \"Refresh page\".", true, false); } }; },