|
@@ -5,6 +5,7 @@ import cn.dev33.satoken.exception.NotPermissionException;
|
|
|
import com.xjrsoft.common.enums.ResponseCode;
|
|
import com.xjrsoft.common.enums.ResponseCode;
|
|
|
import com.xjrsoft.common.model.result.R;
|
|
import com.xjrsoft.common.model.result.R;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.skywalking.apm.toolkit.trace.ActiveSpan;
|
|
|
import org.springframework.validation.BindException;
|
|
import org.springframework.validation.BindException;
|
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.validation.FieldError;
|
|
import org.springframework.validation.FieldError;
|
|
@@ -32,6 +33,8 @@ public class GlobalExceptionHandler {
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public R globalExceptionHandler(Exception e){
|
|
public R globalExceptionHandler(Exception e){
|
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
+ // 使用SkyWalking的Trace Context记录错误信息
|
|
|
|
|
+ ActiveSpan.error(e.getMessage());
|
|
|
return R.error(ResponseCode.INTERNAL_SERVER_ERROR.getCode(),e.getMessage());
|
|
return R.error(ResponseCode.INTERNAL_SERVER_ERROR.getCode(),e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -45,6 +48,8 @@ public class GlobalExceptionHandler {
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public R notLoginExceptionHandler(NotLoginException e){
|
|
public R notLoginExceptionHandler(NotLoginException e){
|
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
+ // 使用SkyWalking的Trace Context记录错误信息
|
|
|
|
|
+ ActiveSpan.error(e.getMessage());
|
|
|
return R.error(ResponseCode.UN_AUTHORIZED.getCode(),ResponseCode.UN_AUTHORIZED.getMessage());
|
|
return R.error(ResponseCode.UN_AUTHORIZED.getCode(),ResponseCode.UN_AUTHORIZED.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -57,6 +62,8 @@ public class GlobalExceptionHandler {
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public R notPermissionExceptionHandler(NotPermissionException e){
|
|
public R notPermissionExceptionHandler(NotPermissionException e){
|
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
+ // 使用SkyWalking的Trace Context记录错误信息
|
|
|
|
|
+ ActiveSpan.error(e.getMessage());
|
|
|
return R.error(ResponseCode.UN_AUTHORIZED.getCode(),e.getMessage());
|
|
return R.error(ResponseCode.UN_AUTHORIZED.getCode(),e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -76,9 +83,13 @@ public class GlobalExceptionHandler {
|
|
|
if (!errors.isEmpty()) {
|
|
if (!errors.isEmpty()) {
|
|
|
// 这里列出了全部错误参数,按正常逻辑,只需要第一条错误即可
|
|
// 这里列出了全部错误参数,按正常逻辑,只需要第一条错误即可
|
|
|
FieldError fieldError = (FieldError) errors.get(0);
|
|
FieldError fieldError = (FieldError) errors.get(0);
|
|
|
|
|
+ // 使用SkyWalking的Trace Context记录错误信息
|
|
|
|
|
+ ActiveSpan.error(fieldError.getDefaultMessage());
|
|
|
return R.error(fieldError.getDefaultMessage());
|
|
return R.error(fieldError.getDefaultMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 使用SkyWalking的Trace Context记录错误信息
|
|
|
|
|
+ ActiveSpan.error(e.getMessage());
|
|
|
return R.error("请求参数错误");
|
|
return R.error("请求参数错误");
|
|
|
}
|
|
}
|
|
|
|
|
|