Skip to content

Commit b681b9a

Browse files
committed
feat: 添加错误码枚举类和状态码枚举类
1 parent bd3aa0b commit b681b9a

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package top.cadecode.simple.constant;
2+
3+
import lombok.Getter;
4+
5+
/**
6+
* @author Li Jun
7+
* @date 2021/8/24
8+
* @description 错误码枚举类
9+
*/
10+
@Getter
11+
public enum ErrorEnum {
12+
13+
// 认证与权限
14+
NO_TOKEN(1000, "用户未登录", StatusEnum.NO_AUTH),
15+
TOKEN_ERROR(1001, "用户令牌错误", StatusEnum.NO_AUTH),
16+
TOKEN_EXPIRED(1002, "用户令牌已过期", StatusEnum.NO_AUTH),
17+
NO_AUTHORITY(1003, "用户权限不足", StatusEnum.FORBIDDEN),
18+
;
19+
20+
private final Integer code;
21+
private final String reason;
22+
private final StatusEnum statusEnum;
23+
24+
ErrorEnum(Integer code, String reason, StatusEnum statusEnum) {
25+
this.code = code;
26+
this.reason = reason;
27+
this.statusEnum = statusEnum;
28+
}
29+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package top.cadecode.simple.constant;
2+
3+
import lombok.Getter;
4+
5+
/**
6+
* @author Li Jun
7+
* @date 2021/8/24
8+
* @description http 状态码枚举
9+
*/
10+
@Getter
11+
public enum StatusEnum {
12+
13+
// 成功
14+
OK(200, "请求成功"),
15+
OK_ADD(201, "添加成功"),
16+
OK_DEL(202, "删除成功"),
17+
OK_UPDATE(203, "更新成功"),
18+
19+
// 客户端错误
20+
BAD_REQ(400, "请求错误"),
21+
NO_AUTH(401, "请求未经认证"),
22+
FORBIDDEN(403, "请求被拒绝"),
23+
NOT_EXIT(404, "资源不存在"),
24+
NOT_FIT(405, "请求方式不合适"),
25+
TOO_MUCH(429, "请求过于频繁"),
26+
27+
// 服务端错误
28+
FAIL(500, "内部服务错误"),
29+
INVALID_PROXY(502, "代理无效"),
30+
TEMP_INVALID(503, "服务暂时失效"),
31+
PROXY_TIME_OUT(504, "代理超时"),
32+
;
33+
34+
private final Integer status;
35+
private final String message;
36+
37+
StatusEnum(Integer status, String message) {
38+
this.status = status;
39+
this.message = message;
40+
}
41+
}

0 commit comments

Comments
 (0)