|
@@ -22,7 +22,7 @@ import com.game.common.utils.StringUtils;
|
|
|
*
|
|
|
* @author recruit
|
|
|
*/
|
|
|
-//@RestControllerAdvice
|
|
|
+@RestControllerAdvice
|
|
|
public class GlobalExceptionHandler
|
|
|
{
|
|
|
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
|
@@ -34,7 +34,7 @@ public class GlobalExceptionHandler
|
|
|
public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request)
|
|
|
{
|
|
|
String requestURI = request.getRequestURI();
|
|
|
- log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage());
|
|
|
+ log.error("请求地址'{}',权限校验失败'{}'", requestURI, e);
|
|
|
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权");
|
|
|
}
|
|
|
|
|
@@ -57,6 +57,7 @@ public class GlobalExceptionHandler
|
|
|
public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request)
|
|
|
{
|
|
|
log.error(e.getMessage(), e);
|
|
|
+ log.info("程序异常:{}", e);
|
|
|
Integer code = e.getCode();
|
|
|
return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
|
|
|
}
|
|
@@ -70,6 +71,7 @@ public class GlobalExceptionHandler
|
|
|
String requestURI = request.getRequestURI();
|
|
|
e.printStackTrace();
|
|
|
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
|
|
|
+ log.info("程序异常:{}", e);
|
|
|
return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
|
|
|
}
|
|
|
|
|
@@ -81,6 +83,7 @@ public class GlobalExceptionHandler
|
|
|
{
|
|
|
String requestURI = request.getRequestURI();
|
|
|
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
|
|
|
+ log.info("程序异常:{}", e);
|
|
|
return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
|
|
|
}
|
|
|
|
|
@@ -92,6 +95,7 @@ public class GlobalExceptionHandler
|
|
|
{
|
|
|
String requestURI = request.getRequestURI();
|
|
|
log.error("请求地址'{}',发生未知异常.,{}", requestURI, e);
|
|
|
+ log.info("程序异常:{}", e);
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
}
|
|
|
|
|
@@ -103,6 +107,7 @@ public class GlobalExceptionHandler
|
|
|
{
|
|
|
String requestURI = request.getRequestURI();
|
|
|
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
|
|
+ log.info("程序异常:{}", e);
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
}
|
|
|
|
|
@@ -113,6 +118,7 @@ public class GlobalExceptionHandler
|
|
|
public AjaxResult handleBindException(BindException e)
|
|
|
{
|
|
|
log.error(e.getMessage(), e);
|
|
|
+ log.info("程序异常:{}", e);
|
|
|
String message = e.getAllErrors().get(0).getDefaultMessage();
|
|
|
return AjaxResult.error(message);
|
|
|
}
|
|
@@ -124,6 +130,7 @@ public class GlobalExceptionHandler
|
|
|
public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e)
|
|
|
{
|
|
|
log.error(e.getMessage(), e);
|
|
|
+ log.info("程序异常:{}", e);
|
|
|
String message = e.getBindingResult().getFieldError().getDefaultMessage();
|
|
|
return AjaxResult.error(message);
|
|
|
}
|