diff --git a/Runtime/Client/EndPointClass.cs b/Runtime/Client/EndPointClass.cs index 0aab85fc..f266daf0 100644 --- a/Runtime/Client/EndPointClass.cs +++ b/Runtime/Client/EndPointClass.cs @@ -27,22 +27,50 @@ public EndPointClass(string endPoint, LootLockerHTTPMethod httpMethod, LootLocke public string WithPathParameter(object arg0) { - return string.Format(endPoint, WebUtility.UrlEncode(arg0.ToString())); + try { + return string.Format(endPoint, WebUtility.UrlEncode(arg0?.ToString() ?? "null")); + } + catch (FormatException e) + { + LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameter \"{WebUtility.UrlEncode(arg0?.ToString() ?? "null")}\": {e}", LootLockerLogger.LogLevel.Error); + return endPoint; + } } public string WithPathParameters(object arg0, object arg1) { - return string.Format(endPoint, WebUtility.UrlEncode(arg0.ToString()), WebUtility.UrlEncode(arg1.ToString())); + try { + return string.Format(endPoint, WebUtility.UrlEncode(arg0?.ToString() ?? "null"), WebUtility.UrlEncode(arg1?.ToString() ?? "null")); + } + catch (FormatException e) + { + LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg1?.ToString() ?? "null")}\": {e}", LootLockerLogger.LogLevel.Error); + return endPoint; + } } public string WithPathParameters(object arg0, object arg1, object arg2) { - return string.Format(endPoint, WebUtility.UrlEncode(arg0.ToString()), WebUtility.UrlEncode(arg1.ToString()), WebUtility.UrlEncode(arg2.ToString())); + try { + return string.Format(endPoint, WebUtility.UrlEncode(arg0?.ToString() ?? "null"), WebUtility.UrlEncode(arg1?.ToString() ?? "null"), WebUtility.UrlEncode(arg2?.ToString() ?? "null")); + } + catch (FormatException e) + { + LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg1?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg2?.ToString() ?? "null")}\": {e}", LootLockerLogger.LogLevel.Error); + return endPoint; + } } public string WithPathParameters(object arg0, object arg1, object arg2, object arg3) { - return string.Format(endPoint, WebUtility.UrlEncode(arg0.ToString()), WebUtility.UrlEncode(arg1.ToString()), WebUtility.UrlEncode(arg2.ToString()), WebUtility.UrlEncode(arg3.ToString())); + try { + return string.Format(endPoint, WebUtility.UrlEncode(arg0?.ToString() ?? "null"), WebUtility.UrlEncode(arg1?.ToString() ?? "null"), WebUtility.UrlEncode(arg2?.ToString() ?? "null"), WebUtility.UrlEncode(arg3?.ToString() ?? "null")); + } + catch (FormatException e) + { + LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg1?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg2?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg3?.ToString() ?? "null")}\": {e}", LootLockerLogger.LogLevel.Error); + return endPoint; + } } } } diff --git a/Runtime/Client/LootLockerHTTPClient.cs b/Runtime/Client/LootLockerHTTPClient.cs index 96a9ff8d..5157db3f 100644 --- a/Runtime/Client/LootLockerHTTPClient.cs +++ b/Runtime/Client/LootLockerHTTPClient.cs @@ -566,8 +566,11 @@ private void CallListenersAndMarkDone(LootLockerHTTPExecutionQueueItem execution executionItem.Done = true; response.requestContext = new LootLockerRequestContext(executionItem.RequestData.ForPlayerWithUlid, executionItem.RequestData.RequestStartTime); executionItem.Response = response; + if (!CompletedRequestIDs.Contains(executionItem.RequestData.RequestId)) + { + CompletedRequestIDs.Add(executionItem.RequestData.RequestId); + } executionItem.RequestData.CallListenersWithResult(response); - CompletedRequestIDs.Add(executionItem.RequestData.RequestId); } private IEnumerator RefreshSession(string refreshForPlayerUlid, string forExecutionItemId, Action onSessionRefreshedCallback) diff --git a/Runtime/Client/LootLockerHttpRequestData.cs b/Runtime/Client/LootLockerHttpRequestData.cs index 51d4976b..4bc2cb99 100644 --- a/Runtime/Client/LootLockerHttpRequestData.cs +++ b/Runtime/Client/LootLockerHttpRequestData.cs @@ -87,7 +87,14 @@ public void CallListenersWithResult(LootLockerResponse response) { foreach(var listener in Listeners) { - listener?.Invoke(response); + try + { + listener?.Invoke(response); + } + catch (Exception e) + { + LootLockerLogger.Log($"Exception thrown in HTTP request listener for request id {RequestId}. Exception was: {e}.", LootLockerLogger.LogLevel.Error); + } } HaveListenersBeenInvoked = true; } diff --git a/Runtime/Game/Utilities/LootLockerHttpUtilities.cs b/Runtime/Game/Utilities/LootLockerHttpUtilities.cs index 5881d8a6..1f2a9c97 100644 --- a/Runtime/Game/Utilities/LootLockerHttpUtilities.cs +++ b/Runtime/Game/Utilities/LootLockerHttpUtilities.cs @@ -59,7 +59,7 @@ public string Build() foreach (KeyValuePair pair in _queryParams) { - if (string.IsNullOrEmpty(pair.Value)) + if (string.IsNullOrEmpty(pair.Key) || string.IsNullOrEmpty(pair.Value)) continue; if (query.Length > 1)