Skip to content

Commit

Permalink
Improved HttpRequest.GetResponse exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Mar 27, 2022
1 parent 5033a6f commit 484dfff
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Skybrud.Essentials.Http/HttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ public virtual IHttpResponse GetResponse(Action<HttpWebRequest> callback) {

#endif

} catch (AggregateException ex) {

if (ex.InnerException is WebException web && web.Status == WebExceptionStatus.ProtocolError) {
return HttpResponse.GetFromWebResponse(web.Response as HttpWebResponse, this);
}

throw;

} catch (WebException ex) {
if (ex.Status != WebExceptionStatus.ProtocolError) throw;
return HttpResponse.GetFromWebResponse(ex.Response as HttpWebResponse, this);
Expand Down

0 comments on commit 484dfff

Please sign in to comment.