ludc
2023-11-20 5e449c8bba2273313fd25457cae653a0f340c910
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
package com.vci.ubcs.starter.exception;
 
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springblade.core.log.exception.ServiceException;
import com.vci.ubcs.starter.web.util.MessageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.log.exception.ServiceException;
 
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.MessageFormat;
 
public class VciBaseException extends ServiceException {
    private Logger log = LoggerFactory.getLogger(this.getClass());
    public static final String paramNull = "com.vci.base.paramNull";
    public static final String fieldValueRepeat = "com.vci.base.fieldValueRepeat";
    public static final String objectNotFoundInDb = "com.vci.base.objectNotFoundInDb";
    public static final String tsNotEqual = "com.vci.base.tsNotEqual";
    public static final String dateValueFormatError = "com.vci.base.dateValueForamtError";
    public static final String notLogin = "com.vci.base.notLogin";
    public static final String notRight = "com.vci.base.notRight";
    public static final String notDataRight = "com.vci.base.notDataRight";
    public static final String notUIRight = "com.vci.base.notUIRight";
    public static final String connectCorbaFail = "com.vci.base.connectCorbaFail";
    public static final String corbaNotConfig = "com.vci.base.corbaNotConfig ";
    private String code;
    private Object[] objs = new Object[0];
 
    public VciBaseException(String code) {
        super(code);
        this.code = code;
    }
 
    public VciBaseException(String code, Object[] objs) {
        super(code);
        this.code = code;
        this.objs = objs;
    }
 
    public VciBaseException(String code, Object[] objs, Throwable e) {
        super(code);
        this.code = code;
        this.objs = objs;
    }
 
    public String getCode() {
        return this.code;
    }
 
    public void setCode(String code) {
        this.code = code;
    }
 
    public Object[] getObjs() {
        return this.objs;
    }
 
    public void setObjs(Object[] objs) {
        this.objs = objs;
    }
 
    public String getErrorMsg() {
        if (!(this instanceof VciBaseException) && !this.getClass().getSuperclass().equals(VciBaseException.class)) {
            return this instanceof Exception ? this.getMessage() : this.code;
        } else {
            if (StringUtils.isNotBlank(this.code)) {
                this.code = MessageUtils.get(this.code, this.objs);
            }
 
            this.code = MessageFormat.format(this.code, this.objs);
            return this.code;
        }
    }
 
    /**
     * 获取异常信息
     * @param e 异常对象
     * @return 异常对象上的所有内容
     */
    public static String getErrorMsgByE(Throwable e){
        if(e == null){
            return "未知错误";
        }
        if( e.getClass()!= null && e.getClass().getSuperclass()!= null &&
            (e.getClass().getSuperclass().equals(RuntimeException.class)
                || e.getClass().getSuperclass().getName().endsWith(".VciBaseException")
                || e.getClass().getName().endsWith(".VciBaseException"))){
            //说明是我们自定义的异常类
            try {
                Method errorMethod = e.getClass().getMethod("getErrorMsg");
                if(errorMethod != null ){
                    return (String)errorMethod.invoke(e);
                }
            } catch (NoSuchMethodException e1) {
                return e.getMessage();
            } catch (IllegalAccessException e1) {
                return e.getMessage();
            } catch (InvocationTargetException e1) {
                return e.getMessage();
            }
        }
        return e.getMessage();
    }
 
    @Override
    public String getMessage() {
        return this.getCode() + "," + this.getErrorMsg();
    }
 
}