欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

根据错误信息返回code

程序员文章站 2022-05-24 10:45:54
...


根据错误信息返回code

代码如下(示例):

//根据错误信息返回
    public LinkedHashMap<String,Object> CodeMap(String error,Integer status) {

        LinkedHashMap<String, Object> errorMap = new LinkedHashMap<>();
        String content = error.trim().replaceAll("\r|\n", "").replace(" ", "");
        if (status == 0) {
            if (Pattern.matches(".*SQLIntegrityConstraintViolationException.*", content)) {
                errorMap.put("code", DefaultApiResultCode.G1100.getCode());
                errorMap.put("message", DefaultApiResultCode.G1100.getMessage());
            } else if (Pattern.matches(".*SQLSyntaxErrorException.*", content)) {
                errorMap.put("code", DefaultApiResultCode.G1101.getCode());
                errorMap.put("message", DefaultApiResultCode.G1101.getMessage());
            }
        } else if (status == 1) {
            if (Pattern.matches(".*SQLIntegrityConstraintViolationException.*", content)) {
                errorMap.put("code", DefaultApiResultCode.G1102.getCode());
                errorMap.put("message", DefaultApiResultCode.G1102.getMessage());
            } else if (Pattern.matches(".*SQLSyntaxErrorException.*", content)) {
                errorMap.put("code", DefaultApiResultCode.G1103.getCode());
                errorMap.put("message", DefaultApiResultCode.G1103.getMessage());
            }
        }
        return  errorMap;
    }