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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/**
* 结果错误码接口
*
* @author Ethan Wang
*/
public interface ResultCode {
/**
* 业务状态码
*
* @return
*/
int getCode();
/**
* 业务状态消息
*
* @return
*/
String getMessage();
}
/**
* 公共错误码 <p>路径区分业务模块</p>
*
* @author Ethan Wang
*/
public enum BaseResultCode implements ResultCode {
OK(0, "OK"),
ERROR(-1, "ERROR"),
SUCCESS(200, "SUCCESS"),
NULL(998, "系统错误 NULL"),
UNKNOWN_ERROR(999, "Unknown Error!"),
/**
* 权限部分
*/
AUTHENTICATION_EXCEPTION(1000, "权限异常"),
SIGN_VERIFY_FAILED(1001, "签名验证失败"),
UNAUTHORIZED(1002, "未登录,请先登录。"),
BAD_CREDENTIALS(1003, "用户名或密码错误,请确认。"),
WRONG_PASSWORD(1004, "密码错误,请确认。"),
USERNAME_NOT_FOUND(1005, "用户名不存在。"),
CAPTCHA_MISMATCH(1006, "验证码不匹配"),
NOT_BINDING_WECHAT_QRCODE(1007, "未绑定微信开放平台网页应用二维码登陆"),
/**
* 用户输入
*/
VALID_ERROR(2000, "参数校验错误"),
DB_NOT_EXIST(2001, "数据库不存在"),
DB_EXIST(2002, "数据库已存在"),
DB_INSERT_FAILED(2002, "数据库插入失败"),
SERVICE_FALLBACK_SYS(3000, "系统服务 fallback"),
SERVICE_FALLBACK_SMS(3001, "短信服务 fallback"),
EXCEL_EXPORT_FAILED(4000, "Excel 导出失败"),
/**
* 调用第三方服务发生错误
*/
THIRD_PART_SERVICE_ERROR(90000, "调用第三方服务发生错误"),
ALI_SMS_SERVER_ERROR(90001, "阿里短信服务异常"),
WECHAT_OPEN_PLATFORM_ERROR(90002, "微信开放平台异常"),
/**
* 第二方服务调用发生错误
*/
S_INFRA_ERROR(100000, "INFRA错误"),
S_SYSTEM_ERROR(110000, "SYS错误"),
S_MES_ERROR(120000, "MES错误"),
S_ERP_ERROR(130000, "ERP错误"),
S_CRM_ERROR(140000, "CRM错误"),
S_WMS_ERROR(150000, "WMS错误"),
S_SCM_ERROR(160000, "SCM错误"),
S_AUTH_ERROR(170000, "AUTH错误"),
S_CROSS_LOGIN_ERROR(180000, "CROSS LOGIN错误"),
;
private final int code;
private final String message;
private BaseResultCode(int code, String message) {
this.code = code;
this.message = message;
}
@Override
public int getCode() {
return code;
}
@Override
public String getMessage() {
return message;
}
}
public class BaseException extends RuntimeException {
protected ResultCode resultCode;
public BaseException(String message) {
super(message);
resultCode = BaseResultCode.ERROR;
}
public BaseException(ResultCode resultCode) {
super(resultCode.getMessage());
this.resultCode = resultCode;
}
public BaseException(ResultCode resultCode, Throwable cause) {
super(cause);
this.resultCode = resultCode;
}
public BaseException(Throwable cause) {
super(cause);
this.resultCode = BaseResultCode.ERROR;
}
public ResultCode getResultCode() {
return resultCode;
}
}
|