Skip to content

Instantly share code, notes, and snippets.

@ctigeek
Created October 24, 2014 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctigeek/b9223f760e7472f5f736 to your computer and use it in GitHub Desktop.
Save ctigeek/b9223f760e7472f5f736 to your computer and use it in GitHub Desktop.
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