AppFriendlyException.cs
2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using NCC.Dependency;
using Microsoft.AspNetCore.Http;
using System;
using System.Runtime.Serialization;
namespace NCC.FriendlyException
{
/// <summary>
/// 自定义友好异常类
/// </summary>
[SuppressSniffer]
public class AppFriendlyException : Exception
{
/// <summary>
/// 构造函数
/// </summary>
public AppFriendlyException() : base()
{
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="message"></param>
/// <param name="errorCode"></param>
public AppFriendlyException(string message, object errorCode) : base(message)
{
ErrorMessage = message;
ErrorCode = errorCode;
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="message"></param>
/// <param name="errorCode"></param>
/// <param name="innerException"></param>
public AppFriendlyException(string message, object errorCode, Exception innerException) : base(message, innerException)
{
ErrorMessage = message;
ErrorCode = errorCode;
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
public AppFriendlyException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <summary>
/// 错误码
/// </summary>
public object ErrorCode { get; set; }
/// <summary>
/// 错误消息(支持 Object 对象)
/// </summary>
public object ErrorMessage { get; set; }
/// <summary>
/// 状态码
/// </summary>
public int StatusCode { get; set; } = StatusCodes.Status500InternalServerError;
/// <summary>
/// 是否是数据验证异常
/// </summary>
public bool ValidationException { get; set; } = false;
}
}