Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Assets/Talo Game Services/Talo/Runtime/APIs/BaseAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ protected async Task<string> Call(
return await Call(uri, method, content, headers, continuity);
}

throw new PlayerAuthException(errorCode, new Exception(message));
if (uri.AbsolutePath.Contains("/v1/players/auth/"))
{
throw new PlayerAuthException(errorCode, new Exception(message));
}
else
{
throw new RequestException(www.responseCode, new Exception(message), www.downloadHandler.text);
}
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions Assets/Talo Game Services/Talo/Runtime/APIs/PlayersAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum DebouncedOperation

public event Action<PlayerAlias> OnIdentified;
public event Action OnIdentificationStarted;
public event Action OnIdentificationFailed;
public event Action<IdentifyException> OnIdentificationFailed;
public event Action OnIdentityCleared;
public event Action<RejectedProp[]> OnPropsRejected;

Expand Down Expand Up @@ -75,21 +75,21 @@ public async Task<PlayerAlias> Identify(string service, string identifier)

var uri = new Uri($"{baseUrl}/identify?service={service}&identifier={identifier}");

PlayersIdentifyResponse res;
try
{
var json = await Call(uri, "GET");

var res = JsonUtility.FromJson<PlayersIdentifyResponse>(json);
var alias = res.alias;
alias.WriteOfflineAlias();
return await HandleIdentifySuccess(alias, res.socketToken);
res = JsonUtility.FromJson<PlayersIdentifyResponse>(json);
}
catch
catch (Exception ex)
{
await Talo.PlayerAuth.SessionManager.ClearSession();
OnIdentificationFailed?.Invoke();
OnIdentificationFailed?.Invoke(IdentifyException.FromException(ex));
throw;
}

res.alias.WriteOfflineAlias();
return await HandleIdentifySuccess(res.alias, res.socketToken);
}

public async Task<PlayerAlias> IdentifySteam(string ticket, string identityClient = "")
Expand Down Expand Up @@ -209,7 +209,7 @@ private async Task<PlayerAlias> IdentifyOffline(string service, string identifie
catch
{
PlayerAlias.DeleteOfflineAlias();
OnIdentificationFailed?.Invoke();
OnIdentificationFailed?.Invoke(new IdentifyException());
throw new Exception("Failed to parse offline player alias");
}

Expand All @@ -218,7 +218,7 @@ private async Task<PlayerAlias> IdentifyOffline(string service, string identifie
return await HandleIdentifySuccess(offlineAlias);
}

OnIdentificationFailed?.Invoke();
OnIdentificationFailed?.Invoke(new IdentifyException());
throw new Exception("No offline player alias found");
}

Expand Down
62 changes: 62 additions & 0 deletions Assets/Talo Game Services/Talo/Runtime/Utils/IdentifyException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using UnityEngine;

namespace TaloGameServices
{
public enum IdentifyErrorCode
{
UNKNOWN_ERROR,
IDENTIFIER_PROFANITY,
IDENTIFIER_TAKEN
}

public class IdentifyException : Exception
{
public IdentifyErrorCode ErrorCode { get; }

public IdentifyException(IdentifyErrorCode code = IdentifyErrorCode.UNKNOWN_ERROR)
: base(code.ToString())
{
ErrorCode = code;
}

public IdentifyException(IdentifyErrorCode code, Exception inner)
: base(code.ToString(), inner)
{
ErrorCode = code;
}

public static IdentifyException FromException(Exception ex)
{
if (ex is RequestException re && !string.IsNullOrEmpty(re.responseBody))
{
return FromResponse(re.responseBody);
}

return new IdentifyException();
}

private static IdentifyException FromResponse(string body)
{
if (string.IsNullOrEmpty(body))
{
return new IdentifyException();
}

try
{
var parsed = JsonUtility.FromJson<ErrorResponse>(body);
if (parsed != null && !string.IsNullOrEmpty(parsed.errorCode) &&
Enum.TryParse(parsed.errorCode, out IdentifyErrorCode code))
{
return new IdentifyException(code);
}
}
catch
{
}

return new IdentifyException();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading