summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail/Transport/ErrorChecker.cs
diff options
context:
space:
mode:
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