HttpException.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Net;
  3. namespace OSHttpServer.Exceptions
  4. {
  5. /// <summary>
  6. /// All HTTP based exceptions will derive this class.
  7. /// </summary>
  8. public class HttpException : Exception
  9. {
  10. private readonly HttpStatusCode _code;
  11. /// <summary>
  12. /// Create a new HttpException
  13. /// </summary>
  14. /// <param name="code">http status code (sent in the response)</param>
  15. /// <param name="message">error description</param>
  16. public HttpException(HttpStatusCode code, string message) : base(code + ": " + message)
  17. {
  18. _code = code;
  19. }
  20. /// <summary>
  21. /// Create a new HttpException
  22. /// </summary>
  23. /// <param name="code">http status code (sent in the response)</param>
  24. /// <param name="message">error description</param>
  25. /// <param name="inner">inner exception</param>
  26. public HttpException(HttpStatusCode code, string message, Exception inner)
  27. : base(code + ": " + message, inner)
  28. {
  29. _code = code;
  30. }
  31. /// <summary>
  32. /// status code to use in the response.
  33. /// </summary>
  34. public HttpStatusCode HttpStatusCode
  35. {
  36. get { return _code; }
  37. }
  38. }
  39. }