summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail/Transport/ErrorChecker.cs
diff options
context:
space:
mode:
authorElmer Thomas <elmer@thinkingserious.com>2016-04-27 18:38:57 -0700
committerElmer Thomas <elmer@thinkingserious.com>2016-04-27 18:38:57 -0700
commit8db5b1b63066d08105e7bedf622a0db0e5ae5ff9 (patch)
tree721785d33df7526e82d5ad0945acf67953a72e66 /SendGrid/SendGridMail/Transport/ErrorChecker.cs
parent172686ed8c1615b1cc1c508c55f31fe9c399b75e (diff)
downloadsendgrid-csharp-8db5b1b63066d08105e7bedf622a0db0e5ae5ff9.zip
sendgrid-csharp-8db5b1b63066d08105e7bedf622a0db0e5ae5ff9.tar.gz
sendgrid-csharp-8db5b1b63066d08105e7bedf622a0db0e5ae5ff9.tar.bz2
Preparing for deploy
Diffstat (limited to 'SendGrid/SendGridMail/Transport/ErrorChecker.cs')
-rw-r--r--SendGrid/SendGridMail/Transport/ErrorChecker.cs57
1 files changed, 0 insertions, 57 deletions
diff --git a/SendGrid/SendGridMail/Transport/ErrorChecker.cs b/SendGrid/SendGridMail/Transport/ErrorChecker.cs
deleted file mode 100644
index 035d2b8..0000000
--- a/SendGrid/SendGridMail/Transport/ErrorChecker.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-namespace SendGrid
-{
- using System;
- using System.IO;
- using System.Net;
- using System.Net.Http;
- using System.Threading.Tasks;
- using System.Xml;
-
- using Exceptions;
-
- public static class ErrorChecker
- {
- public static void CheckForErrors(HttpResponseMessage response)
- {
- CheckForErrors(response, response.Content.ReadAsStreamAsync().Result);
- }
-
- public static async Task CheckForErrorsAsync(HttpResponseMessage response)
- {
- CheckForErrors(response, await response.Content.ReadAsStreamAsync());
- }
-
- private static void CheckForErrors(HttpResponseMessage response, Stream stream)
- {
- if (response.StatusCode != HttpStatusCode.OK)
- {
- using (var reader = XmlReader.Create(stream))
- {
- while (reader.Read())
- {
- if (!reader.IsStartElement())
- {
- continue;
- }
-
- switch (reader.Name)
- {
- case "result":
- continue;
- case "message":
- continue;
- case "errors":
- reader.ReadToFollowing("error");
- var message = reader.ReadElementContentAsString("error", reader.NamespaceURI);
- throw new InvalidApiRequestException(response.StatusCode, new[] { message }, response.ReasonPhrase);
- case "error":
- throw new ProtocolViolationException();
- default:
- throw new ArgumentException("Unknown element: " + reader.Name);
- }
- }
- }
- }
- }
- }
-} \ No newline at end of file