InternalException.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Grpc.Extension.Abstract.Model;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace Grpc.Extension.Abstract
  6. {
  7. /// <summary>
  8. /// Grpc.Extension内部异常
  9. /// </summary>
  10. public class InternalException : Exception
  11. {
  12. private int Code { get; set; }
  13. /// <summary>
  14. /// InternalException
  15. /// </summary>
  16. /// <param name="code"></param>
  17. public InternalException(int code)
  18. {
  19. this.SetCode(code);
  20. }
  21. /// <summary>
  22. /// InternalException
  23. /// </summary>
  24. /// <param name="code"></param>
  25. /// <param name="message"></param>
  26. public InternalException(int code, string message) : base(message)
  27. {
  28. this.SetCode(code);
  29. }
  30. /// <summary>
  31. /// InternalException
  32. /// </summary>
  33. /// <param name="code"></param>
  34. /// <param name="message"></param>
  35. /// <param name="innerException"></param>
  36. public InternalException(int code, string message, Exception innerException) : base(message, innerException)
  37. {
  38. this.SetCode(code);
  39. }
  40. /// <summary>
  41. /// SetCode
  42. /// </summary>
  43. /// <param name="code"></param>
  44. public void SetCode(int code)
  45. {
  46. this.Code = GrpcErrorCode.DefaultErrorCode + code;
  47. this.Data.Add("ErrorCode", this.Code);
  48. }
  49. }
  50. }