forked from kidgrow-microservices-platform

luliqiang
2020-12-31 6fb14149d62199cfcc0448c82eb2f51f9c5181de
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
package com.kidgrow.common.exception;
 
import com.kidgrow.common.exception.code.BaseExceptionCode;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @Description: 业务异常,用于在处理业务逻辑时,进行抛出的异常<br>
 * @Project: <br>
 * @CreateDate: Created in 2020/2/11 11:59 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 */
public class BizException extends KidgrowException{
    private static final long serialVersionUID = -3843907364558373817L;
 
    public BizException(String message) {
        super(-1, message);
    }
 
    public BizException(int code, String message) {
        super(code, message);
    }
 
    /**
     * 实例化异常
     *
     * @param code    自定义异常编码
     * @param message 自定义异常消息
     * @return
     */
    public static BizException wrap(int code, String message) {
        return new BizException(code, message);
    }
 
    public static BizException wrap(String message) {
        return new BizException(-1, message);
    }
 
    public static BizException validFail(String message) {
        return new BizException(-9, message);
    }
 
    public static BizException wrap(BaseExceptionCode ex) {
        return new BizException(ex.getCode(), ex.getMsg());
    }
 
    @Override
    public String toString() {
        return "BizException [message=" + getMsg() + ", code=" + getCode() + "]";
    }
 
}