|
@@ -5,7 +5,6 @@ import cn.dev33.satoken.exception.NotPermissionException;
|
|
|
import cn.dev33.satoken.exception.NotRoleException;
|
|
import cn.dev33.satoken.exception.NotRoleException;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
-import com.cyksj.common.util.StringUtil;
|
|
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
import com.cyksj.enums.GatewayResponse;
|
|
@@ -39,22 +38,9 @@ public class GlobalExceptionHandler {
|
|
|
|
|
|
|
|
@ExceptionHandler(value = {Exception.class})
|
|
@ExceptionHandler(value = {Exception.class})
|
|
|
public Result<String> handleNoteException(Exception e) {
|
|
public Result<String> handleNoteException(Exception e) {
|
|
|
- StringBuilder builder = new StringBuilder(32);
|
|
|
|
|
- builder.append(request.getRequestURI()).append(" -- > ");
|
|
|
|
|
-
|
|
|
|
|
- StackTraceElement[] trace = e.getStackTrace();
|
|
|
|
|
- log.info("{}",e);
|
|
|
|
|
- for (StackTraceElement element : trace) {
|
|
|
|
|
- if (StringUtil.startsWith(element.getClassName(), "com.cyksj")) {
|
|
|
|
|
- builder.append(element.getFileName())
|
|
|
|
|
- .append("[").append(element.getLineNumber()).append("]")
|
|
|
|
|
- .append("&");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- builder.deleteCharAt(builder.length() - 1);
|
|
|
|
|
-
|
|
|
|
|
- String message = e.getMessage();
|
|
|
|
|
- String value = builder.toString();
|
|
|
|
|
|
|
+ String requestId = java.util.UUID.randomUUID().toString();
|
|
|
|
|
+ log.error("Request failed requestId={} path={}", requestId, request.getRequestURI(), e);
|
|
|
|
|
+ String message = e instanceof BusinessRuntimeException ? e.getMessage() : "系统异常,请稍后重试";
|
|
|
GatewayApiCode apiCode = null;
|
|
GatewayApiCode apiCode = null;
|
|
|
if (e instanceof BusinessRuntimeException) {
|
|
if (e instanceof BusinessRuntimeException) {
|
|
|
BusinessRuntimeException ee = (BusinessRuntimeException) e;
|
|
BusinessRuntimeException ee = (BusinessRuntimeException) e;
|
|
@@ -84,11 +70,11 @@ public class GlobalExceptionHandler {
|
|
|
NotPermissionException ee = (NotPermissionException) e;
|
|
NotPermissionException ee = (NotPermissionException) e;
|
|
|
apiCode = GatewayApiCode.CMS_USER_NO_PERMISSION;
|
|
apiCode = GatewayApiCode.CMS_USER_NO_PERMISSION;
|
|
|
}
|
|
}
|
|
|
- log.error("全局错误处理: \n Cause: {} \n Value: {}", message, value);
|
|
|
|
|
|
|
+
|
|
|
if (apiCode != null) {
|
|
if (apiCode != null) {
|
|
|
return GatewayResponse.FAIL.newBuilder().buildGatewayCode(apiCode).toResult();
|
|
return GatewayResponse.FAIL.newBuilder().buildGatewayCode(apiCode).toResult();
|
|
|
}
|
|
}
|
|
|
- return GatewayResponse.FAIL.newBuilder().setMsg(message).toResult(value);
|
|
|
|
|
|
|
+ return GatewayResponse.FAIL.newBuilder().setMsg(message).toResult("requestId=" + requestId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@ExceptionHandler(value = ConstraintViolationException.class)
|
|
@ExceptionHandler(value = ConstraintViolationException.class)
|