Explorar o código

GlobalExceptionHandler MissingRequestValueException

MOKASZ\lw12420 %!s(int64=2) %!d(string=hai) anos
pai
achega
c9ef12f3d3

+ 7 - 1
launch-admin/src/main/java/com/webflux/launchadmin/global/GlobalExceptionHandler.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 import org.springframework.web.multipart.MaxUploadSizeExceededException;
+import org.springframework.web.server.MissingRequestValueException;
 import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
 
@@ -50,7 +51,12 @@ public class GlobalExceptionHandler {
         log.warn("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
         return RW.fail(HttpStatus.FORBIDDEN.toString(), "没有权限,请联系管理员授权", Mono.just(e.getMessage()));
     }
-
+    //@ResponseStatus(HttpStatus.BAD_REQUEST)
+    @ExceptionHandler(MissingRequestValueException.class)
+    public Mono<RW<Object>> handleMissingRequestValueException(ServerWebExchange exchange, AccessDeniedException e) {
+        log.warn("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        return RW.fail(HttpStatus.FORBIDDEN.toString(), "请求参数异常", Mono.just(e.getMessage()));
+    }
     @ExceptionHandler(AccountExpiredException.class)
     public Mono<RW<Object>> handleAccountExpiredException(ServerWebExchange exchange, AccountExpiredException e) {
         log.warn("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));