private bool TryGetForwardResponse(IHttpResponse httpResponse, out WebhooksResponse response, out string errorMsg) { response = null; try { if (httpResponse.Status == HttpRequestQueueResult.Success) { if (string.IsNullOrEmpty(httpResponse.ResponseText)) { errorMsg = string.Format("Missing Response."); return(false); } var responseData = Encoding.UTF8.GetString(httpResponse.ResponseData); this.PluginHost.LogDebug("TryGetForwardResponse:" + responseData); if (!responseData.StartsWith("{") && !responseData.EndsWith("}")) { errorMsg = string.Format("Response is not valid json '{0}'.", responseData); return(false); } response = Newtonsoft.Json.JsonConvert.DeserializeObject <WebhooksResponse>(responseData); if (response != null) { if (response.ResultCode == 0) { errorMsg = string.Empty; return(true); } if (response.ResultCode == 255 && string.IsNullOrEmpty(response.Message)) { errorMsg = string.Format("Unexpected Response '{0}'.", responseData); return(false); } errorMsg = string.Format("Error response ResultCode='{0}' Message='{1}'.", response.ResultCode, response.Message); } else { // since we prevalidate, we don't seam to get here errorMsg = string.Format("Unexpected Response '{0}'.", responseData); } } else { errorMsg = string.Format( "'{0}' httpcode={1} webstatus={2} response='{3}', HttpQueueResult={4}.", httpResponse.Reason, httpResponse.HttpCode, httpResponse.WebStatus, httpResponse.ResponseText, httpResponse.Status); } } catch (Exception ex) { // since we prevalidate, we don't seam to get here errorMsg = ex.Message; } return(false); }
private bool TryGetForwardResponse(IHttpResponse httpResponse, out WebhooksResponse response, out string errorMsg) { response = null; try { if (httpResponse.Status == HttpRequestQueueResult.Success) { if (string.IsNullOrEmpty(httpResponse.ResponseText)) { errorMsg = string.Format("Missing Response."); return false; } var responseData = Encoding.UTF8.GetString(httpResponse.ResponseData); this.PluginHost.LogDebug("TryGetForwardResponse:" + responseData); if (!responseData.StartsWith("{") && !responseData.EndsWith("}")) { errorMsg = string.Format("Response is not valid json '{0}'.", responseData); return false; } response = Newtonsoft.Json.JsonConvert.DeserializeObject<WebhooksResponse>(responseData); if (response != null) { if (response.ResultCode == 0) { errorMsg = string.Empty; return true; } if (response.ResultCode == 255 && string.IsNullOrEmpty(response.Message)) { errorMsg = string.Format("Unexpected Response '{0}'.", responseData); return false; } errorMsg = string.Format("Error response ResultCode='{0}' Message='{1}'.", response.ResultCode, response.Message); } else { // since we prevalidate, we don't seam to get here errorMsg = string.Format("Unexpected Response '{0}'.", responseData); } } else { errorMsg = string.Format( "'{0}' httpcode={1} webstatus={2} response='{3}', HttpQueueResult={4}.", httpResponse.Reason, httpResponse.HttpCode, httpResponse.WebStatus, httpResponse.ResponseText, httpResponse.Status); } } catch (Exception ex) { // since we prevalidate, we don't seam to get here errorMsg = ex.Message; } return false; }