Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw an exception when ExecuteTaskAsync fails
- Loading branch information
1 parent
e49f258
commit 43d41ce
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Net; | ||
|
||
namespace RestSharp.Extensions | ||
{ | ||
public static class ResponseStatusExtensions | ||
{ | ||
/// <summary> | ||
/// Convert a <see cref="ResponseStatus"/> to a <see cref="WebException"/> instance. | ||
/// </summary> | ||
/// <param name="responseStatus">The response status.</param> | ||
/// <returns></returns> | ||
/// <exception cref="System.ArgumentOutOfRangeException">responseStatus</exception> | ||
public static WebException ToWebException(this ResponseStatus responseStatus) | ||
{ | ||
switch (responseStatus) | ||
{ | ||
case ResponseStatus.None: | ||
return new WebException("The request could not be processed.", WebExceptionStatus.ServerProtocolViolation); | ||
case ResponseStatus.Error: | ||
return new WebException("An error occured while processing the request.", WebExceptionStatus.ServerProtocolViolation); | ||
case ResponseStatus.TimedOut: | ||
return new WebException("The request timed-out.", WebExceptionStatus.Timeout); | ||
case ResponseStatus.Aborted: | ||
return new WebException("The request was aborted.", WebExceptionStatus.Timeout); | ||
default: | ||
throw new ArgumentOutOfRangeException("responseStatus"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters