forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathApiResponse.cs
58 lines (54 loc) · 1.57 KB
/
ApiResponse.cs
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
namespace Blog.Core.Model
{
public class ApiResponse
{
public int Status { get; set; } = 200;
public string Value { get; set; } = "";
public MessageModel<string> MessageModel = new MessageModel<string>() { };
public ApiResponse(StatusCode apiCode, string msg = null)
{
switch (apiCode)
{
case StatusCode.CODE401:
{
Status = 401;
Value = "很抱歉,您无权访问该接口,请确保已经登录!";
}
break;
case StatusCode.CODE403:
{
Status = 403;
Value = "很抱歉,您的访问权限等级不够,联系管理员!";
}
break;
case StatusCode.CODE404:
{
Status = 404;
Value = "资源不存在!";
}
break;
case StatusCode.CODE500:
{
Status = 500;
Value = msg;
}
break;
}
MessageModel = new MessageModel<string>()
{
status = Status,
msg = Value,
success = apiCode != StatusCode.CODE200
};
}
}
public enum StatusCode
{
CODE200,
CODE401,
CODE403,
CODE404,
CODE500
}
}