diff options
author | Brandon West <brawest@gmail.com> | 2014-10-09 15:52:10 -0600 |
---|---|---|
committer | Brandon West <brawest@gmail.com> | 2014-10-09 15:52:10 -0600 |
commit | 88bbde7219098f8699dfa971e6c88a879e01c3fb (patch) | |
tree | 38ad6fd56c28b405f65eae1f59dd29a1573b2b70 /SendGrid/SendGridMail/Transport/Web.cs | |
parent | fc46788ff6da5e31559e0550607db735ecde4c2d (diff) | |
download | sendgrid-csharp-88bbde7219098f8699dfa971e6c88a879e01c3fb.zip sendgrid-csharp-88bbde7219098f8699dfa971e6c88a879e01c3fb.tar.gz sendgrid-csharp-88bbde7219098f8699dfa971e6c88a879e01c3fb.tar.bz2 |
async exception handling example
Diffstat (limited to 'SendGrid/SendGridMail/Transport/Web.cs')
-rw-r--r-- | SendGrid/SendGridMail/Transport/Web.cs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs index 1458da8..69fed4c 100644 --- a/SendGrid/SendGridMail/Transport/Web.cs +++ b/SendGrid/SendGridMail/Transport/Web.cs @@ -179,7 +179,15 @@ namespace SendGrid var content = await response.Content.ReadAsStreamAsync();
- FindErrorsInResponse(content);
+ 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)
|