添加表内的异常返回类型

master_haizei
grimm 2023-12-29 18:39:07 +08:00
parent 4806c9d71e
commit 0eb673e594
4 changed files with 88 additions and 7 deletions

View File

@ -226,6 +226,10 @@ public enum ErrorCode implements IErrorCode {
this.errMsg = errMsg;
}
public void setCodeId(int codeId) {
this.codeId = codeId;
}
@Override
public int code() {
return codeId;

View File

@ -67,7 +67,7 @@ public class ErrorCodeException extends Exception {
}
public String toString() {
return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&&params.size()!=0)?params.toString():"")+"] ";
return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&& !params.isEmpty())?params.toString():"")+"] ";
}
public List<String> getParams() {
@ -75,6 +75,6 @@ public class ErrorCodeException extends Exception {
}
public String getMessage() {
return "" + super.getMessage();
return super.getMessage();
}
}

View File

@ -0,0 +1,72 @@
package com.ljsd.jieling.exception;
import config.SErrorCodeEerverConfig;
import util.StringUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Description:
* Author: zsx
* CreateDate: 2019/10/21 11:44
*/
public class ErrorTableException extends Exception {
private int id;
private String msg;
private List<String> params;
public ErrorTableException(int id, String msg) {
this.id = id;
this.msg = msg;
}
public ErrorTableException(int id, String msg, List<String> params) {
this.id = id;
this.msg = msg;
this.params = params;
}
public ErrorTableException(int id) {
String message = SErrorCodeEerverConfig.errorTableMap.get(id);
if (StringUtil.isEmpty(message)){
this.id = -1;
this.msg = "操作失败,并未找到错误码:{"+id+"},请联系管理员";
}else {
this.id = id;
this.msg = message;
}
}
public void setId(int id) {
this.id = id;
}
public void setMsg(String msg) {
this.msg = msg;
}
public void setParams(List<String> params) {
this.params = params;
}
public int getCode() {
return this.id;
}
public String getMsg() {
return msg;
}
public String getMessage() {
return super.getMessage();
}
public List<String> getParams() {
return null == params ? new ArrayList<>() : params;
}
public String toString() {
return "[CODE: " + this.getCode() + "][" + this.getMsg() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&& !params.isEmpty())?params.toString():"")+"] ";
}
}

View File

@ -4,13 +4,16 @@ import manager.STableManager;
import manager.Table;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Table(name ="ErrorCodeEerverConfig")
public class SErrorCodeEerverConfig implements BaseConfig {
private static Map<String ,SErrorCodeEerverConfig> errorCodeMap;
private static Map<String ,SErrorCodeEerverConfig> errorCodeMap;
public static Map<Integer,SErrorCodeEerverConfig> errorMap;
public static Map<Integer, String> errorTableMap = new HashMap<>();
private int id;
private String key;
@ -26,13 +29,15 @@ public class SErrorCodeEerverConfig implements BaseConfig {
Map<Integer, SErrorCodeEerverConfig> config = STableManager.getConfig(SErrorCodeEerverConfig.class);
Map<String ,SErrorCodeEerverConfig> errorCodeEerverConfigMap = new ConcurrentHashMap<>();
Map<Integer,SErrorCodeEerverConfig> tempErrorMap = new ConcurrentHashMap<>();
for (Map.Entry<Integer, SErrorCodeEerverConfig> entry :config.entrySet()){
SErrorCodeEerverConfig sErrorCodeEerverConfig = entry.getValue();
errorCodeEerverConfigMap.put(sErrorCodeEerverConfig.getkey(),sErrorCodeEerverConfig);
tempErrorMap.put(sErrorCodeEerverConfig.getid(),sErrorCodeEerverConfig);
Map<Integer,String> tableErrorMap = new HashMap<>();
for (SErrorCodeEerverConfig errorConfig : config.values()) {
errorCodeEerverConfigMap.put(errorConfig.getkey(),errorConfig);
tempErrorMap.put(errorConfig.getid(),errorConfig);
tableErrorMap.put(errorConfig.getid(), errorConfig.getvalue());
}
errorCodeMap = errorCodeEerverConfigMap;
errorMap = tempErrorMap;
errorTableMap = tableErrorMap;
}