Skip to content

Commit 8341822

Browse files
feat: better lobby exceptions handling (#568)
* Added switch-case to only show popups for Lobby exceptions pertinent to the users
1 parent 39b9055 commit 8341822

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

Assets/BossRoom/Scripts/Client/UI/UnityServicesUIHandler.cs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,38 @@ void ServiceErrorHandler(UnityServiceErrorMessage error)
4949

5050
void HandleLobbyError(UnityServiceErrorMessage error)
5151
{
52-
var errorMessage = error.Message;
53-
switch (((LobbyServiceException)error.OriginalException).Reason)
52+
var exception = (LobbyServiceException) error.OriginalException;
53+
if (exception != null)
5454
{
55-
case LobbyExceptionReason.LobbyConflict:
55+
switch (exception.Reason)
5656
{
57-
errorMessage += "\nSee logs for possible causes and solution.";
58-
Debug.LogError($"Got service error {error.Message} with LobbyConflict. Possible conflict cause: Trying to play with two builds on the " +
59-
$"same machine. Please use command line arg '{ProfileManager.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
60-
break;
61-
}
62-
case LobbyExceptionReason.LobbyFull:
63-
{
64-
PopupPanel.ShowPopupPanel("Failed to join lobby", "Lobby is full and can't accept more players");
65-
// Returning out of the function because we replace default popup panel with this.
66-
return;
57+
// If the error is one of the following, the player needs to know about it, so show in a popup message. Otherwise, the log in the console is sufficient.
58+
case LobbyExceptionReason.LobbyConflict:
59+
// LobbyConflict can have multiple causes. Let's add other solutions here if there's other situations that arise for this.
60+
Debug.LogError($"Got service error {error.Message} with LobbyConflict. Possible conflict cause: Trying to play with two builds on the " +
61+
$"same machine. Please use command line arg '{ProfileManager.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
62+
PopupPanel.ShowPopupPanel("Failed to join Lobby due to a conflict", "See logs for more details.");
63+
break;
64+
case LobbyExceptionReason.LobbyNotFound:
65+
PopupPanel.ShowPopupPanel("Lobby Not Found", "Requested lobby not found. See logs for details.");
66+
break;
67+
case LobbyExceptionReason.NoOpenLobbies:
68+
PopupPanel.ShowPopupPanel("Failed to join Lobby", "No accessible lobbies are currently available for quick-join.");
69+
break;
70+
case LobbyExceptionReason.LobbyFull:
71+
PopupPanel.ShowPopupPanel("Failed to join Lobby", "Lobby is full and can't accept more players.");
72+
break;
73+
case LobbyExceptionReason.Unauthorized:
74+
PopupPanel.ShowPopupPanel("Lobby error", "Unauthorized.");
75+
break;
76+
case LobbyExceptionReason.RequestTimeOut:
77+
PopupPanel.ShowPopupPanel("Lobby error", "Request timed out.");
78+
break;
79+
case LobbyExceptionReason.BadRequest:
80+
PopupPanel.ShowPopupPanel("Lobby error", "Received HTTP error 400 Bad Request from Lobby Service. Is the join code correctly formatted?");
81+
break;
6782
}
6883
}
69-
70-
PopupPanel.ShowPopupPanel("Service error: " + error.Title, errorMessage);
7184
}
7285

7386
void OnDestroy()

Assets/BossRoom/Scripts/Shared/Net/UnityServices/Lobbies/LobbyServiceFacade.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -253,28 +253,7 @@ public void RemovePlayerFromLobbyAsync(string uasId, string lobbyId, Action onSu
253253
{
254254
if (m_LocalUser.IsHost)
255255
{
256-
RetrieveLobbyAsync(lobbyId, OnRetrieveSuccess, onFailure);
257-
258-
259-
void OnRetrieveSuccess(Lobby lobby)
260-
{
261-
bool playerFound = false;
262-
foreach (var player in lobby.Players)
263-
{
264-
if (player.Id == uasId)
265-
{
266-
m_LobbyApiInterface.LeaveLobbyAsync(uasId, lobbyId, onSuccess, onFailure);
267-
playerFound = true;
268-
break;
269-
}
270-
}
271-
272-
if (!playerFound)
273-
{
274-
Debug.Log($"Player {uasId} has already left the lobby.");
275-
}
276-
}
277-
256+
m_LobbyApiInterface.LeaveLobbyAsync(uasId, lobbyId, onSuccess, onFailure);
278257
}
279258
else
280259
{

0 commit comments

Comments
 (0)