提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.common.exception; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.exception.enums.ServiceErrorCodeRange; |
|
4 |
import lombok.Data; |
|
5 |
import lombok.EqualsAndHashCode; |
|
6 |
|
|
7 |
/** |
|
8 |
* 业务逻辑异常 Exception |
|
9 |
*/ |
|
10 |
@Data |
|
11 |
@EqualsAndHashCode(callSuper = true) |
|
12 |
public final class ServiceException extends RuntimeException { |
|
13 |
|
|
14 |
/** |
|
15 |
* 业务错误码 |
|
16 |
* |
|
17 |
* @see ServiceErrorCodeRange |
|
18 |
*/ |
|
19 |
private Integer code; |
|
20 |
/** |
|
21 |
* 错误提示 |
|
22 |
*/ |
|
23 |
private String message; |
|
24 |
|
|
25 |
/** |
|
26 |
* 空构造方法,避免反序列化问题 |
|
27 |
*/ |
|
28 |
public ServiceException() { |
|
29 |
} |
|
30 |
|
|
31 |
public ServiceException(ErrorCode errorCode) { |
|
32 |
this.code = errorCode.getCode(); |
|
33 |
this.message = errorCode.getMsg(); |
|
34 |
} |
|
35 |
|
|
36 |
public ServiceException(Integer code, String message) { |
|
37 |
this.code = code; |
|
38 |
this.message = message; |
|
39 |
} |
|
40 |
|
|
41 |
public Integer getCode() { |
|
42 |
return code; |
|
43 |
} |
|
44 |
|
|
45 |
public ServiceException setCode(Integer code) { |
|
46 |
this.code = code; |
|
47 |
return this; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public String getMessage() { |
|
52 |
return message; |
|
53 |
} |
|
54 |
|
|
55 |
public ServiceException setMessage(String message) { |
|
56 |
this.message = message; |
|
57 |
return this; |
|
58 |
} |
|
59 |
|
|
60 |
} |