Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An exception that will encapsulate the details of a web call without embedding the specific response object. Using with RestClient.
//boy am I looking forward to read-only classes in c# ver6.
public class WebResponseException : Exception
public readonly HttpStatusCode StatusCode;
public readonly string RequestUrl;
public readonly string RequestMethod;
public readonly Dictionary<string, string> RequestHeaders;
public readonly Dictionary<string, string> ResponseHeaders;
public readonly string ResponseBody;
public WebResponseException(string message, HttpStatusCode statusCode, string requestUrl,
string requestMethod,
Exception innerException = null,
Dictionary<string, string> requestHeaders = null,
Dictionary<string, string> responseHeaders = null,
string responseBody = null)
: base(message, innerException)
this.StatusCode = statusCode;
this.RequestMethod = requestMethod;
this.RequestUrl = requestUrl;
this.RequestHeaders = requestHeaders ?? new Dictionary<string, string>();
this.ResponseHeaders = responseHeaders ?? new Dictionary<string, string>();
this.ResponseBody = responseBody;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.