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

46 lines
1.7 KiB

  1. using System;
  2. namespace Apewer
  3. {
  4. /// <summary>表示未授权的错误。</summary>
  5. /// <remarks>默认消息:Operation is not authorized.</remarks>
  6. public class UnauthorizedException : Exception
  7. {
  8. static string _default = FixMessage(null);
  9. static string FixMessage(string message)
  10. {
  11. const string Preset = "Operation is not authorized.";
  12. if (message != null)
  13. {
  14. message = message.Trim();
  15. if (!string.IsNullOrEmpty(message)) return message;
  16. }
  17. return Preset;
  18. }
  19. /// <summary>获取或设置默认消息。</summary>
  20. public static string DefaultMessage { get => _default; set => _default = FixMessage(value); }
  21. /// <summary>状态。</summary>
  22. /// <value>Unauthorized</value>
  23. public virtual string Status { get => "Unauthorized"; }
  24. /// <summary>表示未授权的错误,此时应在前端发起授权。</summary>
  25. /// <remarks>默认消息:Operation is not authorized.</remarks>
  26. public UnauthorizedException() : base(DefaultMessage) { }
  27. /// <summary>表示未授权的错误,此时应在前端发起授权。</summary>
  28. /// <remarks>默认消息:Operation is not authorized.</remarks>
  29. public UnauthorizedException(string message) : base(FixMessage(message)) { }
  30. /// <summary>表示未授权的错误,此时应在前端发起授权。</summary>
  31. /// <remarks>默认消息:Operation is not authorized.</remarks>
  32. public UnauthorizedException(string message, Exception innerException) : base(FixMessage(message), innerException) { }
  33. }
  34. }