public static Dictionary <string, object> ParseResponseAsDictionary(IAsyncHTTPClient request, Action <string> errorMessageCallback) { string errorMessage; if (request.IsSuccess() && request.responseCode == 200) { try { var response = Json.Deserialize(request.text) as Dictionary <string, object>; if (response != null) { return(response); } errorMessage = L10n.Tr("Failed to parse JSON."); } catch (Exception e) { errorMessage = string.Format(L10n.Tr("Failed to parse JSON: {0}"), e.Message); } } else { errorMessage = request.text; } errorMessageCallback?.Invoke(errorMessage); return(null); }
private Dictionary <string, object> ParseResponse(IAsyncHTTPClient request) { string errorMessage; if (request.IsSuccess()) { try { var response = Json.Deserialize(request.text) as Dictionary <string, object>; if (response != null) { return(response); } errorMessage = "Failed to parse JSON."; } catch (Exception e) { errorMessage = $"Failed to parse JSON: {e.Message}";; } } else { errorMessage = request.text; } OnOperationError(errorMessage); return(null); }
public static Dictionary <string, object> ParseResponseAsDictionary(IAsyncHTTPClient request) { string errorMessage; if (request.IsSuccess() && request.responseCode == 200) { if (string.IsNullOrEmpty(request.text)) { return(null); } try { var response = Json.Deserialize(request.text) as Dictionary <string, object>; if (response != null) { return(response); } errorMessage = k_InvalidJSONErrorMessage; } catch (Exception e) { errorMessage = $"{k_InvalidJSONErrorMessage} {e.Message}"; } } else { if (request.responseCode == 0 && (string.IsNullOrEmpty(request.text) || request.text.ToLower().Contains("timeout"))) { return(null); } var text = request.text.Length <= 128 ? request.text : request.text.Substring(0, 128) + "..."; errorMessage = $"{k_ServerErrorMessage} \"{text}\" [Code {request.responseCode}]"; } return(string.IsNullOrEmpty(errorMessage) ? null : new Dictionary <string, object> { ["errorMessage"] = errorMessage }); }
public static Dictionary <string, object> ParseResponseAsDictionary(IAsyncHTTPClient request, Action <string> errorMessageCallback) { string errorMessage; if (request.IsSuccess() && request.responseCode == 200) { try { var response = Json.Deserialize(request.text) as Dictionary <string, object>; if (response != null) { return(response); } errorMessage = L10n.Tr("Failed to parse JSON."); } catch (Exception e) { errorMessage = string.Format(L10n.Tr("Failed to parse JSON: {0}"), e.Message); } } else { if (request.responseCode == 0 && string.IsNullOrEmpty(request.text)) { errorMessage = L10n.Tr("Failed to parse response."); } else { var text = request.text.Length <= 128 ? request.text : request.text.Substring(0, 128) + "..."; errorMessage = string.Format(L10n.Tr("Failed to parse response: Code {0} \"{1}\""), request.responseCode, text); } } errorMessageCallback?.Invoke(errorMessage); return(null); }