private static Exception ThrowReworkedCustomException<EX>(WebException we) where EX : ErrorResult { using (System.IO.StreamReader sr = new System.IO.StreamReader(((HttpWebResponse)we.Response).GetResponseStream())) { string response = sr.ReadToEnd().Trim(); ErrorResult result = JsonConvert.DeserializeObject<EX>(response); string message; if (result is OAuthErrorResult) message = string.Format( "The CreateSend OAuth receiver responded with the following error - {0}: {1}", (result as OAuthErrorResult).error, (result as OAuthErrorResult).error_description); else // Regular ErrorResult format. message = string.Format( "The CreateSend API responded with the following error - {0}: {1}", result.Code, result.Message); CreatesendException exception; if (result.Code == "121") exception = new ExpiredOAuthTokenException(message); else exception = new CreatesendException(message); exception.Data.Add("ErrorResponse", response); exception.Data.Add("ErrorResult", result); return exception; } }
private static Exception ThrowReworkedCustomException(WebException we) { using (System.IO.StreamReader sr = new System.IO.StreamReader(((HttpWebResponse)we.Response).GetResponseStream())) { string response = sr.ReadToEnd().Trim(); try { ErrorResult apiExceptionResult = JavaScriptConvert.DeserializeObject <ErrorResult>(response); CreatesendException exception = new CreatesendException(string.Format("The CreateSend API responded with the following error - {0}: {1}", apiExceptionResult.Code, apiExceptionResult.Message)); exception.Data.Add("ErrorResponse", response); exception.Data.Add("ErrorResult", apiExceptionResult); return(exception); } catch (Newtonsoft.Json.JsonSerializationException) { CreatesendException exception = new CreatesendException("The CreateSend API returned an error with addtional data"); exception.Data.Add("ErrorResponse", response); return(exception); } } }
private static Exception ThrowReworkedCustomException(WebException we) { using (System.IO.StreamReader sr = new System.IO.StreamReader(((HttpWebResponse)we.Response).GetResponseStream())) { string response = sr.ReadToEnd().Trim(); try { ErrorResult apiExceptionResult = JavaScriptConvert.DeserializeObject<ErrorResult>(response); CreatesendException exception = new CreatesendException(string.Format("The CreateSend API responded with the following error - {0}: {1}", apiExceptionResult.Code, apiExceptionResult.Message)); exception.Data.Add("ErrorResponse", response); exception.Data.Add("ErrorResult", apiExceptionResult); return exception; } catch (Newtonsoft.Json.JsonSerializationException) { CreatesendException exception = new CreatesendException("The CreateSend API returned an error with addtional data"); exception.Data.Add("ErrorResponse", response); return exception; } } }