Skip to content

Commit d9e3b40

Browse files
committed
Moved service error popup logic to dedicated class
1 parent 7c5f64e commit d9e3b40

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

Assets/BossRoom/Scripts/Client/Game/State/ClientMainMenuState.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void OnAuthSignIn()
103103
void OnSignInFailed()
104104
{
105105
m_SignInSpinner.SetActive(false);
106-
PopupPanel.ShowPopupPanel("Authentication Error", "For some reason we can't authenticate the user anonymously - that typically means that project is not properly set up with Unity services.");
107106
}
108107
}
109108

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Runtime.CompilerServices;
23
using Unity.Multiplayer.Samples.BossRoom.Client;
34
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
45
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
6+
using Unity.Services.Authentication;
57
using Unity.Services.Lobbies;
68
using UnityEngine;
79

@@ -25,26 +27,44 @@ void Initialize(ISubscriber<UnityServiceErrorMessage> serviceError)
2527
void ServiceErrorHandler(UnityServiceErrorMessage error)
2628
{
2729
var errorMessage = error.Message;
28-
if (error.AffectedService == UnityServiceErrorMessage.Service.Lobby)
30+
switch (error.AffectedService)
2931
{
30-
if (error.OriginalException is LobbyServiceException lobbyServiceException)
32+
case UnityServiceErrorMessage.Service.Lobby:
3133
{
32-
if (lobbyServiceException.Reason == LobbyExceptionReason.LobbyConflict)
34+
if ((error.OriginalException is LobbyServiceException {Reason: LobbyExceptionReason.LobbyConflict}))
3335
{
3436
// LobbyConflict can have multiple causes. Let's add other solutions here if there's other situations that arise for this.
3537
errorMessage += "\nSee logs for possible causes and solution.";
3638
Debug.LogError($"Got service error {error.Message} with LobbyConflict. Possible conflict cause: Trying to play with two builds on the " +
3739
$"same machine. Please use command line arg '{ClientMainMenuState.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
40+
3841
}
42+
PopupPanel.ShowPopupPanel("Service error", errorMessage);
43+
break;
3944
}
40-
}
45+
case UnityServiceErrorMessage.Service.Authentication:
46+
{
47+
if (error.OriginalException is AuthenticationException exception)
48+
{
49+
PopupPanel.ShowPopupPanel("Authentication Error",
50+
$"For some reason we can't authenticate the user anonymously - that typically means that project is not properly " +
51+
$"set up with Unity services or that there is no internet connection." +
52+
$" You can still use the Direct IP connection option. {exception.Message}");
4153

42-
PopupPanel.ShowPopupPanel("Service error", errorMessage);
54+
}
55+
break;
56+
}
57+
default:
58+
{
59+
PopupPanel.ShowPopupPanel("Service error", errorMessage);
60+
break;
61+
}
62+
}
4363
}
4464

4565
void OnDestroy()
4666
{
4767
m_Subscriptions.Dispose();
4868
}
4969
}
50-
}
70+
}

Assets/BossRoom/Scripts/Shared/Net/UnityServices/Auth/AuthenticationServiceFacade.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void InjectDependencies(IPublisher<UnityServiceErrorMessage> unityServiceErrorMe
1818
m_UnityServiceErrorMessagePublisher = unityServiceErrorMessagePublisher;
1919
}
2020

21-
void OnServiceException(AuthenticationException e)
21+
void OnServiceException(RequestFailedException e)
2222
{
2323
Debug.LogWarning(e.Message);
2424

@@ -30,7 +30,7 @@ void OnServiceException(AuthenticationException e)
3030
public void DoSignInAsync(Action onSigninComplete, Action onFailed, InitializationOptions initializationOptions)
3131
{
3232
var task = TrySignIn(initializationOptions);
33-
UnityServiceCallsTaskWrapper.RunTask<AuthenticationException>(task, onSigninComplete, onFailed, OnServiceException);
33+
UnityServiceCallsTaskWrapper.RunTask<RequestFailedException>(task, onSigninComplete, onFailed, OnServiceException);
3434
}
3535

3636
async Task TrySignIn(InitializationOptions initializationOptions)

0 commit comments

Comments
 (0)