You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

HttpException.cs 1.4 kB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Net;
  3. namespace Discord.Net
  4. {
  5. public class HttpException : Exception
  6. {
  7. public HttpStatusCode HttpCode { get; }
  8. public int? DiscordCode { get; }
  9. public string Reason { get; }
  10. public IRequest Request { get; }
  11. public HttpException(HttpStatusCode httpCode, IRequest request, int? discordCode = null, string reason = null)
  12. : base(CreateMessage(httpCode, discordCode, reason))
  13. {
  14. HttpCode = httpCode;
  15. Request = request;
  16. DiscordCode = discordCode;
  17. Reason = reason;
  18. }
  19. private static string CreateMessage(HttpStatusCode httpCode, int? discordCode = null, string reason = null)
  20. {
  21. string msg;
  22. if (discordCode != null && discordCode != 0)
  23. {
  24. if (reason != null)
  25. msg = $"The server responded with error {(int)discordCode}: {reason}";
  26. else
  27. msg = $"The server responded with error {(int)discordCode}: {httpCode}";
  28. }
  29. else
  30. {
  31. if (reason != null)
  32. msg = $"The server responded with error {(int)httpCode}: {reason}";
  33. else
  34. msg = $"The server responded with error {(int)httpCode}: {httpCode}";
  35. }
  36. return msg;
  37. }
  38. }
  39. }