Skip to content

Commit abced96

Browse files
author
Mikkel Sørensen
committed
Simply setting errorData | calling error messages
1 parent 18ec6b5 commit abced96

File tree

2 files changed

+15
-80
lines changed

2 files changed

+15
-80
lines changed

Runtime/Client/LootLockerServerApi.cs

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,7 @@ IEnumerator coroutine()
131131
text = webRequest.downloadHandler.text
132132
};
133133

134-
LootLockerErrorData errorData =
135-
LootLockerJson.DeserializeObject<LootLockerErrorData>(webRequest.downloadHandler.text);
136-
if (ErrorIsPreErrorCodes(errorData))
137-
{
138-
errorData = ExpandErrorInformation(webRequest.responseCode, webRequest.downloadHandler.text);
139-
}
140-
141-
response.errorData = errorData;
134+
response.errorData = LootLockerJson.DeserializeObject<LootLockerErrorData>(webRequest.downloadHandler.text);
142135
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Error)(response.errorData.message +
143136
(!string.IsNullOrEmpty(response.errorData.doc_url) ? " -- " + response.errorData.doc_url : ""));
144137
OnServerResponse?.Invoke(response);
@@ -149,76 +142,6 @@ IEnumerator coroutine()
149142

150143
#region Private Methods
151144

152-
private static LootLockerErrorData ExpandErrorInformation(long statusCode, string responseBody)
153-
{
154-
var errorData = new LootLockerErrorData();
155-
switch (statusCode)
156-
{
157-
case 400:
158-
errorData.message = "Bad Request -- Your request has an error.";
159-
errorData.code = "bad_request";
160-
break;
161-
case 401:
162-
errorData.message = "Unauthorized -- Your session_token is invalid.";
163-
errorData.code = "unauthorized";
164-
break;
165-
case 402:
166-
errorData.message = "Payment Required -- Payment failed. Insufficient funds, etc.";
167-
errorData.code = "payment_required";
168-
break;
169-
case 403:
170-
errorData.message = "Forbidden -- You do not have access to this resource.";
171-
errorData.code = "forbidden";
172-
break;
173-
case 404:
174-
errorData.message = "Not Found -- The requested resource could not be found.";
175-
errorData.code = "not_found";
176-
break;
177-
case 405:
178-
errorData.message =
179-
"Method Not Allowed -- The selected http method is invalid for this resource.";
180-
errorData.code = "method_not_allowed";
181-
break;
182-
case 406:
183-
errorData.message = "Not Acceptable -- Purchasing is disabled.";
184-
errorData.code = "not_acceptable";
185-
break;
186-
case 409:
187-
errorData.message =
188-
"Conflict -- Your state is most likely not aligned with the servers.";
189-
errorData.code = "conflict";
190-
break;
191-
case 429:
192-
errorData.message =
193-
"Too Many Requests -- You're being limited for sending too many requests too quickly.";
194-
errorData.code = "too_many_requests";
195-
break;
196-
case 500:
197-
errorData.message =
198-
"Internal Server Error -- We had a problem with our server. Try again later.";
199-
errorData.code = "internal_server_error";
200-
break;
201-
case 503:
202-
errorData.message =
203-
"Service Unavailable -- We're either offline for maintenance, or an error that should be solvable by calling again later was triggered.";
204-
errorData.code = "service_unavailable";
205-
break;
206-
default:
207-
errorData.message = "Unknown error.";
208-
break;
209-
}
210-
211-
errorData.message +=
212-
" " + LootLockerObfuscator.ObfuscateJsonStringForLogging(responseBody);
213-
return errorData;
214-
}
215-
216-
private static bool ErrorIsPreErrorCodes(LootLockerErrorData errorData)
217-
{
218-
// Check if the error uses the "old" error style, not the "new" (https://docs.lootlocker.com/reference/error-codes)
219-
return errorData == null || string.IsNullOrEmpty(errorData.code);
220-
}
221-
222145
private static bool ShouldRetryRequest(long statusCode, int timesRetried)
223146
{
224147
return (statusCode == 401 || statusCode == 403) && LootLockerConfig.current.allowTokenRefresh && CurrentPlatform.Get() != Platforms.Steam && timesRetried < MaxRetries;

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ public class LootLockerErrorData
116116
/// If the request was not a success this property will hold any error messages
117117
/// </summary>
118118
public string message { get; set; }
119+
120+
/// <summary>
121+
/// An easy way of debugging LootLockerErrorData class, example: Debug.Log(onComplete.errorData);
122+
/// </summary>
123+
/// <returns>string used to debug errors</returns>
124+
public override string ToString()
125+
{
126+
return $"We encountered an unexpected server error. Please try again later.\n If the issue persists, please contact LootLocker support and reference the following error details:\n trace ID - {trace_id},\n request ID - {request_id},\n message - {message}.";
127+
}
119128
}
120129

121130
/// <summary>
@@ -174,9 +183,12 @@ public static T Deserialize<T>(LootLockerResponse serverResponse,
174183
{
175184
return LootLockerResponseFactory.Error<T>("Unknown error, please check your internet connection.");
176185
}
177-
else if (serverResponse.errorData != null && !string.IsNullOrEmpty(serverResponse.errorData.code))
186+
else if (serverResponse.errorData != null)
178187
{
179-
return new T() { success = false, errorData = serverResponse.errorData, statusCode = serverResponse.statusCode };
188+
if(!string.IsNullOrEmpty(serverResponse.errorData.code)) {
189+
return new T() { success = false, errorData = serverResponse.errorData, statusCode = serverResponse.statusCode };
190+
}
191+
return new T() { success = false, errorData = serverResponse.errorData };
180192
}
181193

182194
var response = LootLockerJson.DeserializeObject<T>(serverResponse.text, options ?? LootLockerJsonSettings.Default) ?? new T();

0 commit comments

Comments
 (0)