add
This commit is contained in:
@ -3,10 +3,14 @@ package com.qiaoba.common.web.advice;
|
||||
|
||||
import com.qiaoba.common.base.exceptions.ServiceException;
|
||||
import com.qiaoba.common.base.result.AjaxResult;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
*
|
||||
@ -38,8 +42,31 @@ public class ExceptionAdvice {
|
||||
*/
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
@ResponseBody
|
||||
public AjaxResult handlerApiException(ServiceException e) {
|
||||
public AjaxResult handlerServiceException(ServiceException e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验
|
||||
*
|
||||
* @param e MethodArgumentNotValidException
|
||||
* @return AjaxResult
|
||||
*/
|
||||
@ExceptionHandler({MethodArgumentNotValidException.class})
|
||||
@ResponseBody
|
||||
public AjaxResult handlerValidException(MethodArgumentNotValidException e) {
|
||||
return AjaxResult.error(Objects.isNull(e.getBindingResult().getFieldError()) ? e.getMessage() : e.getBindingResult().getFieldError().getDefaultMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验
|
||||
*
|
||||
* @param e BindException
|
||||
* @return AjaxResult
|
||||
*/
|
||||
@ExceptionHandler({BindException.class})
|
||||
@ResponseBody
|
||||
public AjaxResult handlerValidException(BindException e) {
|
||||
return AjaxResult.error(Objects.isNull(e.getBindingResult().getFieldError()) ? e.getMessage() : e.getBindingResult().getFieldError().getDefaultMessage());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user