From 7821fdb701fb91d3da574aa29af18224e27f7d62 Mon Sep 17 00:00:00 2001 From: Elivo Date: Thu, 10 Jul 2025 17:35:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20UnauthorizedException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apewer/UnauthorizedException.cs | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Apewer/UnauthorizedException.cs diff --git a/Apewer/UnauthorizedException.cs b/Apewer/UnauthorizedException.cs new file mode 100644 index 0000000..6931754 --- /dev/null +++ b/Apewer/UnauthorizedException.cs @@ -0,0 +1,46 @@ +using System; + +namespace Apewer +{ + + /// 表示未授权的错误。 + /// 默认消息:Operation is not authorized. + public class UnauthorizedException : Exception + { + + static string _default = FixMessage(null); + + static string FixMessage(string message) + { + const string Preset = "Operation is not authorized."; + if (message != null) + { + message = message.Trim(); + if (!string.IsNullOrEmpty(message)) return message; + } + + return Preset; + } + + /// 获取或设置默认消息。 + public static string DefaultMessage { get => _default; set => _default = FixMessage(value); } + + /// 状态。 + /// Unauthorized + public virtual string Status { get => "Unauthorized"; } + + /// 表示未授权的错误,此时应在前端发起授权。 + /// 默认消息:Operation is not authorized. + public UnauthorizedException() : base(DefaultMessage) { } + + /// 表示未授权的错误,此时应在前端发起授权。 + /// 默认消息:Operation is not authorized. + public UnauthorizedException(string message) : base(FixMessage(message)) { } + + /// 表示未授权的错误,此时应在前端发起授权。 + /// 默认消息:Operation is not authorized. + public UnauthorizedException(string message, Exception innerException) : base(FixMessage(message), innerException) { } + + } + +}