
top.lshaci.framework.web.exception.handler.GlobalExceptionHandler Maven / Gradle / Ivy
The newest version!
package top.lshaci.framework.web.exception.handler;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.lshaci.framework.common.exception.BaseException;
import top.lshaci.framework.common.model.JsonResponse;
import top.lshaci.framework.web.model.ExceptionMessage;
import top.lshaci.framework.web.utils.GlobalExceptionUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import static cn.hutool.http.HttpStatus.HTTP_BAD_REQUEST;
/**
* Global exception handler
* 0.0.4:
*
* 添加参数验证异常
*
*
* 1.0.4:
*
* 使用GlobalExceptionUtils来获取自定义的异常消息
*
*
* 1.0.8:
*
* 删除参数验证失败异常中的日志信息
*
*
* 1.1.0:
*
* 使用 {@code @RestControllerAdvice} 替换 {@code @RestController} 和 {@code @ResponseBody}
*
*
* @author lshaci
* @version 1.1.0
* @since 0.0.3
*/
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final Log log = LogFactory.get();
/**
* Base exception handler
*
* @param e the exception
* @return json response
*/
@ExceptionHandler(BaseException.class)
public JsonResponse
© 2015 - 2025 Weber Informatics LLC | Privacy Policy