summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail/Transport/Web.cs
diff options
context:
space:
mode:
authorBrandon West <brawest@gmail.com>2015-04-22 18:42:54 -0600
committerBrandon West <brawest@gmail.com>2015-04-22 18:42:54 -0600
commit648b5a2c40a1d66afbec6c3c82dc2870cc748903 (patch)
tree1556d41a7104841405af531ac41a87b4ad19f5b4 /SendGrid/SendGridMail/Transport/Web.cs
parent3739bf91ac7e6227370cd0acc0a3ba08462ae690 (diff)
parent2705013d2b58d0e614205606c87c4ad2ecec8259 (diff)
downloadsendgrid-csharp-648b5a2c40a1d66afbec6c3c82dc2870cc748903.zip
sendgrid-csharp-648b5a2c40a1d66afbec6c3c82dc2870cc748903.tar.gz
sendgrid-csharp-648b5a2c40a1d66afbec6c3c82dc2870cc748903.tar.bz2
fix merge conflicts
Diffstat (limited to 'SendGrid/SendGridMail/Transport/Web.cs')
-rw-r--r--SendGrid/SendGridMail/Transport/Web.cs52
1 files changed, 4 insertions, 48 deletions
diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs
index 4d2f484..81e7c72 100644
--- a/SendGrid/SendGridMail/Transport/Web.cs
+++ b/SendGrid/SendGridMail/Transport/Web.cs
@@ -57,8 +57,8 @@ namespace SendGrid
var content = new MultipartFormDataContent();
AttachFormParams(message, content);
AttachFiles(message, content);
- var response = await _client.PostAsync(Endpoint, content);
- await CheckForErrorsAsync(response);
+ var response = await _client.PostAsync(Endpoint + ".xml", content);
+ await ErrorChecker.CheckForErrorsAsync(response);
}
#region Support Methods
@@ -107,52 +107,8 @@ namespace SendGrid
}
}
- private static void FindErrorsInResponse(Stream content)
- {
- using (var reader = XmlReader.Create(content))
- {
- while (reader.Read())
- {
- if (!reader.IsStartElement()) continue;
- switch (reader.Name)
- {
- case "result":
- break;
- case "message": // success
- if (reader.ReadToNextSibling("errors"))
- throw new ProtocolViolationException();
- return;
- case "error": // failure
- throw new ProtocolViolationException();
- default:
- throw new ArgumentException("Unknown element: " + reader.Name);
- }
- }
- }
- }
-
- private static string[] GetErrorsInResponse(Stream content)
- {
- var xmlDoc = new XmlDocument();
- xmlDoc.Load(content);
- return (from XmlNode errorNode in xmlDoc.SelectNodes("//error") select errorNode.InnerText).ToArray();
- }
-
- private static async Task CheckForErrorsAsync(HttpResponseMessage response)
- {
- var content = await response.Content.ReadAsStreamAsync();
-
- var errors = GetErrorsInResponse(content);
-
- // API error
- if (errors.Any())
- throw new InvalidApiRequestException(response.StatusCode, errors, response.ReasonPhrase);
-
- // Other error
- if (response.StatusCode != HttpStatusCode.OK)
- FindErrorsInResponse(content);
- }
-
+
+
internal List<KeyValuePair<String, String>> FetchFormParams(ISendGrid message)
{
var result = new List<KeyValuePair<string, string>>