diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/exception/GlobalExceptionHandler.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/exception/GlobalExceptionHandler.java index 066e2109..0526f812 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/exception/GlobalExceptionHandler.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/exception/GlobalExceptionHandler.java @@ -2,10 +2,12 @@ import com.abin.mallchat.common.common.domain.vo.response.ApiResult; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; 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.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -16,6 +18,7 @@ public class GlobalExceptionHandler { /** * validation参数校验异常 */ + @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(value = MethodArgumentNotValidException.class) public ApiResult methodArgumentNotValidExceptionExceptionHandler(MethodArgumentNotValidException e) { StringBuilder errorMsg = new StringBuilder(); @@ -28,6 +31,7 @@ public ApiResult methodArgumentNotValidExceptionExceptionHandler(MethodArgumentN /** * validation参数校验异常 */ + @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(value = BindException.class) public ApiResult bindException(BindException e) { StringBuilder errorMsg = new StringBuilder(); @@ -40,6 +44,7 @@ public ApiResult bindException(BindException e) { /** * 处理空指针的异常 */ + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(value = NullPointerException.class) public ApiResult exceptionHandler(NullPointerException e) { log.error("null point exception!The reason is: ", e); @@ -49,6 +54,7 @@ public ApiResult exceptionHandler(NullPointerException e) { /** * 未知异常 */ + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(value = Exception.class) public ApiResult systemExceptionHandler(Exception e) { log.error("system exception!The reason is:{}", e.getMessage(), e); @@ -58,6 +64,7 @@ public ApiResult systemExceptionHandler(Exception e) { /** * 自定义校验异常(如参数校验等) */ + @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(value = BusinessException.class) public ApiResult businessExceptionHandler(BusinessException e) { log.info("business exception!The reason is:{}", e.getMessage(), e); @@ -67,6 +74,7 @@ public ApiResult businessExceptionHandler(BusinessException e) { /** * http请求方式不支持 */ + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ExceptionHandler(HttpRequestMethodNotSupportedException.class) public ApiResult handleException(HttpRequestMethodNotSupportedException e) { log.error(e.getMessage(), e); @@ -76,6 +84,7 @@ public ApiResult handleException(HttpRequestMethodNotSupportedException e) /** * 限流异常 */ + @ResponseStatus(HttpStatus.TOO_MANY_REQUESTS) @ExceptionHandler(value = FrequencyControlException.class) public ApiResult frequencyControlExceptionHandler(FrequencyControlException e) { log.info("frequencyControl exception!The reason is:{}", e.getMessage(), e);