/// <summary> /// To be used with a callback which passes the response with result including status success or error code, request url and any body text. /// </summary> /// <param name="callback">Callback.</param> public void Result(Action <RestResponse> callback = null) { RestResult result = GetRestResult(false); if (result.IsError) { Debug.LogWarning("Response error status:" + result.StatusCode + " code:" + request.responseCode + " error:" + result.ErrorMessage + " request url:" + request.url); callback(new RestResponse(result.ErrorMessage, result.StatusCode, request.url, request.downloadHandler.text)); } else { callback(new RestResponse(result.StatusCode, request.url, request.downloadHandler.text)); } }
private RestResult GetRestResult(bool expectedBodyContent = true) { HttpStatusCode statusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), request.responseCode.ToString()); RestResult result = new RestResult(statusCode); if (result.IsError) { result.ErrorMessage = "Response failed with status: " + statusCode.ToString(); return(result); } if (expectedBodyContent && string.IsNullOrEmpty(request.downloadHandler.text)) { result.IsError = true; result.ErrorMessage = "Response has empty body"; return(result); } return(result); }