From 49e1fb18fbefe6a58dd751e80e394c6778dde97f Mon Sep 17 00:00:00 2001 From: zigzag Date: Sun, 11 Jun 2023 23:22:07 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=85=A8=E5=B1=80=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BB=86=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/GlobalExceptionHandler.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/exception/GlobalExceptionHandler.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/exception/GlobalExceptionHandler.java index 66e0b70..fad1667 100644 --- a/mallchat-common/src/main/java/com/abin/mallchat/common/common/exception/GlobalExceptionHandler.java +++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/exception/GlobalExceptionHandler.java @@ -3,6 +3,7 @@ package com.abin.mallchat.common.common.exception; import com.abin.mallchat.common.common.domain.vo.response.ApiResult; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.BindException; +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; @@ -62,4 +63,14 @@ public class GlobalExceptionHandler { log.info("business exception!The reason is:{}", e.getMessage(), e); return ApiResult.fail(e.getErrorCode(), e.getMessage()); } -} \ No newline at end of file + + /** + * http请求方式不支持 + */ + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public ApiResult handleException(HttpRequestMethodNotSupportedException e) { + log.error(e.getMessage(), e); + return ApiResult.fail(-1, String.format("不支持'%s'请求", e.getMethod())); + } + +}