异常提示提交

master_haizei
grimm 2024-05-27 10:54:17 +08:00
parent 53b88a7811
commit 10c76f1332
4 changed files with 38 additions and 27 deletions

View File

@ -4,6 +4,7 @@ import com.ljsd.GameApplication;
import com.ljsd.jieling.core.function.FunctionContext;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.exception.ErrorTableException;
import com.ljsd.jieling.exception.ErrorUtil;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.GlobleSystemLogic;
@ -114,10 +115,9 @@ public class HandlerLogicThread extends Thread{
try {
transaction.callback();
//内部codeErr统一处理
if(e instanceof ErrorCodeException){
int errCode = ErrorUtil.getExceptionErrorCodeValue(e);
LOGGER.error("An unusual ErrorCodeException occurred for the user={} errCode={} e={}",
session.getUid(), errCode, e);
if(e instanceof ErrorCodeException || e instanceof ErrorTableException){
int errCode = ErrorUtil.getExceptionErrorCode(e);
LOGGER.error("An unusual ErrorCodeException occurred for the user={} errCode={} e={}", session.getUid(), errCode, e);
if (errCode <= 0) {
//打印堆栈定位错误
LOGGER.error(ErrorUtil.getExceptionStackTraceFileLineAndMethod(e));
@ -125,7 +125,7 @@ public class HandlerLogicThread extends Thread{
LOGGER.info(e.toString());
LOGGER.error(ErrorUtil.getExceptionStackTraceFileLineAndMethod(e));
}
MessageUtil.sendErrorResponse(session, errCode, session.getLastMsgId() + 1,(ErrorCodeException)e);
MessageUtil.sendErrorResponse(session, errCode, session.getLastMsgId() + 1, e);
return;
}
@ -140,7 +140,7 @@ public class HandlerLogicThread extends Thread{
}
UserManager.addUser(user);
MessageUtil.sendErrorResponse(session, 0, session.getLastMsgId() + 1,"");
// MessageUtil.sendErrorCode(session,session.getLastMsgId()+1, SErrorCodeEerverConfig.getI18NMessage("bug_unify_txt"));
// MessageUtil.sendErrorCode(session,session.getLastMsgId()+1, SErrorCodeEerverConfig.getI18NMessage("bug_unify_txt"));
}catch (Exception e1){
LOGGER.error("e={}",e1);
}

View File

@ -10,25 +10,21 @@ public class ErrorUtil {
public ErrorUtil() {
}
private static ErrorCode getExceptionErrorCode(Throwable e) {
if (e == null) {
return ErrorCode.UNKNOWN;
} else {
public static int getExceptionErrorCode(Throwable e) {
int code = ErrorCode.UNKNOWN.code();
if (e != null){
Throwable t = e;
ErrorCode r = ErrorCode.UNKNOWN;
do {
if (t instanceof ErrorCodeException) {
r = ((ErrorCodeException) t).getCode();
code = ((ErrorCodeException) t).getCode().code();
}
else if (t instanceof ErrorTableException){
code = ((ErrorTableException) t).getCode();
}
t = t.getCause();
} while (t != null);
return r;
}
}
public static int getExceptionErrorCodeValue(Throwable e) {
return getExceptionErrorCode(e).code();
return code;
}
public static String getExceptionMessage(Throwable e) {
@ -40,7 +36,7 @@ public class ErrorUtil {
do {
if (!(t instanceof ErrorCodeException)) {
builder.append(t.getClass().getSimpleName()).append(":").append(t.getMessage()).append(" ");
} else if (t.getMessage() != null && t.getMessage().length() > 0) {
} else if (t.getMessage() != null && !t.getMessage().isEmpty()) {
builder.append(t.getMessage()).append(" ");
}
t = t.getCause();
@ -58,7 +54,11 @@ public class ErrorUtil {
} else {
StringBuilder builder = new StringBuilder();
if(e instanceof ErrorCodeException){
builder.append(e.toString());
builder.append(e);
builder.append(System.getProperty("line.separator"));
}
else if (e instanceof ErrorTableException){
builder.append(e);
builder.append(System.getProperty("line.separator"));
}
Throwable t = e;

View File

@ -5,6 +5,7 @@ import com.ljsd.jieling.core.FunctionIdEnum;
import com.ljsd.jieling.core.VipPrivilegeType;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.exception.ErrorTableException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.logic.GlobleSystemLogic;
import com.ljsd.jieling.logic.dao.TeamEnum;
@ -175,15 +176,15 @@ public class DuoduiTowerLogic {
}
List<SDuoDuiTower> towers = SDuoDuiTower.duoduiMap.get(type).get(tier);
if (towers == null || towers.isEmpty() || towers.get(0).getIncome() == null || towers.get(0).getIncome().length == 0){
String format = MessageFormat.format("多队获取奖励失败,配置表奖励不存在,类型:{0},当前层数:{1},uid:{3}", type, tier, user.getId());
String format = MessageFormat.format("多队获取奖励失败,配置表奖励不存在,类型:{0},当前层数:{1},uid:{2}", type, tier, user.getId());
throw new ErrorCodeException(format);
}
int[][] income = towers.get(0).getIncome();
int count;
if (operate == 1){//普通领取
if (nowInt < time +60){
String format = MessageFormat.format("多队获取奖励失败,时间不足1分钟,类型:{0},当前层数:{1},time:{2},uid:{3}", type, tier, time, user.getId());
throw new ErrorCodeException(format);
LOGGER.error("多队获取奖励失败,时间不足1分钟,类型:{},当前层数:{},time:{},uid:{}", type, tier, time, user.getId());
throw new ErrorTableException(162);//时间不足1分钟
}
int num = (nowInt - time) / 60;
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.Duoduita_accumulation_time);

View File

@ -13,6 +13,7 @@ import com.ljsd.jieling.core.SimpleTransaction;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.exception.ErrorTableException;
import com.ljsd.jieling.exception.ErrorUtil;
import com.ljsd.jieling.globals.Global;
import com.ljsd.jieling.logic.OnlineUserManager;
@ -266,16 +267,25 @@ public class MessageUtil {
}
//服务器逻辑错误返回,一般情况是业务逻辑错误
public static void sendErrorResponse(ISession session,int errorCode,int msgId, ErrorCodeException e) throws Exception {
sendErrorResponse(session, errorCode, msgId, ErrorUtil.getExceptionMessage(e),e.getParams());
public static void sendErrorResponse(ISession session,int errorCode,int msgId, Exception e) {
List<String> list = new ArrayList<>();
if (e instanceof ErrorCodeException){
ErrorCodeException e1 = (ErrorCodeException) e;
list = e1.getParams();
}
else if (e instanceof ErrorTableException){
ErrorTableException e2 = (ErrorTableException) e;
list = e2.getParams();
}
sendErrorResponse(session, errorCode, msgId, ErrorUtil.getExceptionMessage(e), list);
}
//服务器逻辑错误返回,一般情况是业务逻辑错误
public static void sendErrorResponse(ISession session,int errorCode,int msgId, String errMsg) throws Exception {
public static void sendErrorResponse(ISession session,int errorCode,int msgId, String errMsg) {
sendErrorResponse(session, errorCode, msgId, errMsg,new ArrayList<>());
}
//服务器逻辑错误返回,一般情况是业务逻辑错误
public static void sendErrorResponse(ISession session,int errorCode,int msgId, String errMsg,List<String> param) throws Exception {
public static void sendErrorResponse(ISession session,int errorCode,int msgId, String errMsg,List<String> param) {
GeneratedMessage generatedMessage = null;
if( null == errMsg){
errMsg="";