Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 503d28b

Browse files
committed
Pass-thru exception
1 parent aebf8ab commit 503d28b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/ServiceStack.Text/HttpUtils.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public static string HeadFromUrl(this string url, string accept = "*/*",
201201
}
202202

203203
public static Task<string> GetStringFromUrlAsync(this string url, string accept = "*/*",
204-
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null)
204+
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null)
205205
{
206206
return SendStringToUrlAsync(url, accept: accept, requestFilter: requestFilter, responseFilter: responseFilter);
207207
}
@@ -348,20 +348,24 @@ public static Task<string> SendStringToUrlAsync(this string url, string method =
348348
}
349349

350350
var taskWebRes = webReq.GetResponseAsync();
351-
return taskWebRes.ContinueWith(task =>
352-
{
353-
var webRes = task.Result;
354-
if (responseFilter != null)
351+
return taskWebRes
352+
.ContinueWith(task =>
355353
{
356-
responseFilter((HttpWebResponse)webRes);
357-
}
354+
if (task.Exception != null)
355+
throw task.Exception;
358356

359-
using (var stream = webRes.GetResponseStream())
360-
using (var reader = new StreamReader(stream))
361-
{
362-
return reader.ReadToEnd();
363-
}
364-
}, TaskContinuationOptions.NotOnFaulted | TaskContinuationOptions.OnlyOnRanToCompletion);
357+
var webRes = task.Result;
358+
if (responseFilter != null)
359+
{
360+
responseFilter((HttpWebResponse)webRes);
361+
}
362+
363+
using (var stream = webRes.GetResponseStream())
364+
using (var reader = new StreamReader(stream))
365+
{
366+
return reader.ReadToEnd();
367+
}
368+
}, TaskContinuationOptions.NotOnCanceled);
365369
}
366370

367371
public static string SendStringToUrl(this string url, string method = null,

0 commit comments

Comments
 (0)