5 Commits
2875b0be66
...
452659df1c
| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
452659df1c |
Merge branch 'master' of http://gitea/apewer/apewer-dotnet
|
1 month ago |
|
|
c1907bff9c |
API 反射支持 Unparallel 特性。
|
1 month ago |
|
|
80502fbcfe |
Json 支持序列化 byte[] 属性,且支持自定义方法。
|
1 month ago |
|
|
2be2c663e8 |
添加 UnparallelAttribute 特性,使用路由时,可阻止并行。
|
2 months ago |
|
|
b82991bd6d |
增加 IApiException,用于自定义 Response 的 status 值。
|
2 months ago |
12 changed files with 258 additions and 20 deletions
-
24Apewer/ForbiddenException.cs
-
47Apewer/Json.cs
-
46Apewer/NotFoundException.cs
-
7Apewer/RedundanceException.cs
-
5Apewer/UnauthorizedException.cs
-
16Apewer/UnparallelAttribute.cs
-
14Apewer/Web/ApiAction.cs
-
7Apewer/Web/ApiApplication.cs
-
7Apewer/Web/ApiFunction.cs
-
71Apewer/Web/ApiProcessor.cs
-
8Apewer/Web/ApiUtility.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 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Apewer |
||||
|
{ |
||||
|
|
||||
|
/// <summary>表示方法不可并行。</summary>
|
||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] |
||||
|
public sealed class UnparallelAttribute : Attribute |
||||
|
{ |
||||
|
|
||||
|
/// <summary></summary>
|
||||
|
public static implicit operator bool(UnparallelAttribute unparallel) => unparallel != null; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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