服务项目

This commit is contained in:
starrySky
2024-03-31 15:46:23 +08:00
parent c7f81acbe5
commit 2356636387
19 changed files with 886 additions and 9 deletions

View File

@@ -9,6 +9,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -54,8 +55,22 @@ public class GlobalExceptionHandler {
return R.error("系统出现内部错误,请联系管理员");
}
/**
* 请求方法异常
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public R httpRequestMethodNotSupportedException() {
return R.error("请求方法异常");
}
/**
* 请求参数异常
*
* @param e HttpRequestMethodNotSupportedException
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
public R methodArgumentNotValidException(MethodArgumentNotValidException e, HttpServletRequest request) {
public R methodArgumentNotValidException(MethodArgumentNotValidException e) {
BindingResult bindingResult = e.getBindingResult();
StringBuilder errorMessageBuilder = new StringBuilder();
for (FieldError error : bindingResult.getFieldErrors()) {
@@ -64,8 +79,13 @@ public class GlobalExceptionHandler {
return R.error("请求参数异常," + errorMessageBuilder);
}
/**
* 自定义异常
*
* @param e CustomException
*/
@ExceptionHandler(CustomException.class)
public R customException(CustomException e, HttpServletRequest request) {
public R customException(CustomException e) {
return R.error(e.getMessage());
}
}