Permalink
Browse files

make Deliver and CheckForErrors methods async

  • Loading branch information...
1 parent b11fed6 commit 7d436f6cb48b1fe8f12949fea77bb7ea87fe3cc3 @brandonmwest brandonmwest committed Jul 27, 2013
Showing with 4 additions and 4 deletions.
  1. +4 −4 SendGrid/SendGridMail/Transport/Web.cs
@@ -48,7 +48,7 @@ internal Web(NetworkCredential credentials, bool https = true)
/// Delivers a message over SendGrid's Web interface
/// </summary>
/// <param name="message"></param>
- public void Deliver(ISendGrid message)
+ public async void Deliver(ISendGrid message)
{
var client = new HttpClient
{
@@ -58,7 +58,7 @@ public void Deliver(ISendGrid message)
var content = new MultipartFormDataContent();
AttachFormParams(message, content);
AttachFiles(message, content);
- var response = client.PostAsync(Endpoint + ".xml", content).Result;
+ var response = await client.PostAsync(Endpoint + ".xml", content);
CheckForErrors(response);
}
@@ -107,15 +107,15 @@ private void AttachFiles(ISendGrid message, MultipartFormDataContent content)
}
}
- private void CheckForErrors (HttpResponseMessage response)
+ private async void CheckForErrors (HttpResponseMessage response)
{
//transport error
if (response.StatusCode != HttpStatusCode.OK) {
throw new Exception(response.ReasonPhrase);
}
//TODO: check for HTTP errors... don't throw exceptions just pass info along?
- var content = response.Content.ReadAsStreamAsync().Result;
+ var content = await response.Content.ReadAsStreamAsync();
using (var reader = XmlReader.Create(content))
{

1 comment on commit 7d436f6

@brandonmwest
Contributor

Going to remove this for now. Might be worth adding methods that are async but they should be separate be called e.g. CheckForErrorsAsync

Please sign in to comment.