CosServerException.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.Serialization;
  4. using System.Text;
  5. using COSXML.Model.Tag;
  6. namespace COSXML.CosException
  7. {
  8. /// <summary>
  9. /// 服务器异常,通常是一个非正确的服务器响应,例如权限错误、服务不可用等。
  10. /// <see href="Model.Tag.CosServerError"/>
  11. /// </summary>
  12. [Serializable]
  13. public class CosServerException : System.ApplicationException
  14. {
  15. /// <summary>
  16. /// http status code
  17. /// </summary>
  18. public int statusCode;
  19. /// <summary>
  20. /// http status message
  21. /// </summary>
  22. public string statusMessage;
  23. /// <summary>
  24. /// cos server error code
  25. /// </summary>
  26. public string errorCode;
  27. /// <summary>
  28. /// cos server error message
  29. /// </summary>
  30. public string errorMessage;
  31. /// <summary>
  32. /// cos server requestId for tracking error
  33. /// </summary>
  34. public string requestId;
  35. /// <summary>
  36. /// cos server trace id
  37. /// </summary>
  38. public string traceId;
  39. /// <summary>
  40. /// cos server resuorce
  41. /// </summary>
  42. public string resource;
  43. public CosServerException(int statusCode, string statusMessage, CosServerError serverError)
  44. : this(statusCode, statusMessage)
  45. {
  46. if (serverError != null)
  47. {
  48. this.resource = serverError.resource;
  49. this.errorCode = serverError.code;
  50. this.errorMessage = serverError.message;
  51. this.requestId = serverError.requestId;
  52. this.traceId = serverError.traceId;
  53. }
  54. }
  55. public CosServerException(int statusCode, string statusMessage)
  56. : base("CosServerException: {" + statusCode + "} - {" + statusMessage + "}")
  57. {
  58. this.statusCode = statusCode;
  59. this.statusMessage = statusMessage;
  60. }
  61. public void SetCosServerError(CosServerError serverError)
  62. {
  63. if (serverError != null)
  64. {
  65. this.resource = serverError.resource;
  66. this.errorCode = serverError.code;
  67. this.errorMessage = serverError.message;
  68. this.requestId = serverError.requestId;
  69. this.traceId = serverError.traceId;
  70. }
  71. }
  72. public string GetInfo()
  73. {
  74. StringBuilder builder = new StringBuilder();
  75. builder.Append("(")
  76. .Append("statusCode = ").Append(statusCode).Append(", statusMessage = ").Append(statusMessage)
  77. .Append(", errorCode = ").Append(errorCode).Append(", errorMessage = ").Append(errorMessage)
  78. .Append(", requestId = ").Append(requestId).Append(", traceId = ").Append(traceId)
  79. .Append(", resouce = ").Append(resource)
  80. .Append(")");
  81. return builder.ToString();
  82. }
  83. }
  84. }