6 changed files with 139 additions and 15 deletions
-
24Apewer/ForbiddenException.cs
-
46Apewer/NotFoundException.cs
-
7Apewer/RedundanceException.cs
-
5Apewer/UnauthorizedException.cs
-
48Apewer/Web/ApiProcessor.cs
-
16Apewer/Web/IApiException.cs
@ -0,0 +1,24 @@ |
|||
using Apewer.Web; |
|||
using System; |
|||
|
|||
namespace Apewer |
|||
{ |
|||
|
|||
/// <summary>表示被禁止访问的错误。</summary>
|
|||
public sealed class ForbiddenException : Exception, IApiException |
|||
{ |
|||
|
|||
const string DefaultMessage = "禁止访问。"; |
|||
|
|||
/// <summary>表示禁止访问的状态。</summary>
|
|||
public string Status { get => "Forbidden"; } |
|||
|
|||
/// <summary></summary>
|
|||
public ForbiddenException(string message = DefaultMessage) : base(message.IsEmpty() ? DefaultMessage : message) { } |
|||
|
|||
/// <summary></summary>
|
|||
public override string ToString() => $"<ForbiddenException> {Message}"; |
|||
|
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
using Apewer.Web; |
|||
using System; |
|||
|
|||
namespace Apewer |
|||
{ |
|||
|
|||
/// <summary>表示目标资源不存在的错误。</summary>
|
|||
public class NotFoundException : Exception, IApiException |
|||
{ |
|||
|
|||
static string _default = FixMessage(null); |
|||
|
|||
static string FixMessage(string message) |
|||
{ |
|||
const string Preset = "Resource not found."; |
|||
if (message != null) |
|||
{ |
|||
message = message.Trim(); |
|||
if (!string.IsNullOrEmpty(message)) return message; |
|||
} |
|||
|
|||
return Preset; |
|||
} |
|||
|
|||
/// <summary>获取或设置默认消息。</summary>
|
|||
public static string DefaultMessage { get => _default; set => _default = FixMessage(value); } |
|||
|
|||
/// <summary>状态。</summary>
|
|||
/// <value>Unauthorized</value>
|
|||
public virtual string Status { get => "Not Found"; } |
|||
|
|||
/// <summary>表示目标资源不存在的错误。</summary>
|
|||
/// <remarks>默认消息:Operation is not authorized.</remarks>
|
|||
public NotFoundException() : base(DefaultMessage) { } |
|||
|
|||
/// <summary>表示目标资源不存在的错误。</summary>
|
|||
/// <remarks>默认消息:Operation is not authorized.</remarks>
|
|||
public NotFoundException(string message) : base(FixMessage(message)) { } |
|||
|
|||
/// <summary>表示目标资源不存在的错误。</summary>
|
|||
/// <remarks>默认消息:Operation is not authorized.</remarks>
|
|||
public NotFoundException(string message, Exception innerException) : base(FixMessage(message), innerException) { } |
|||
|
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
namespace Apewer.Web |
|||
{ |
|||
|
|||
/// <summary>执行 API 时发生的异常。</summary>
|
|||
public interface IApiException |
|||
{ |
|||
|
|||
/// <summary>异常状态。</summary>
|
|||
string Status { get; } |
|||
|
|||
/// <summary>错误消息。</summary>
|
|||
string Message { get; } |
|||
|
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue