perf: 全局异常处理细化

This commit is contained in:
zigzag
2023-06-11 23:22:07 +08:00
parent 13dc04d4af
commit 49e1fb18fb

View File

@@ -3,6 +3,7 @@ package com.abin.mallchat.common.common.exception;
import com.abin.mallchat.common.common.domain.vo.response.ApiResult; import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindException; import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -62,4 +63,14 @@ public class GlobalExceptionHandler {
log.info("business exceptionThe reason is{}", e.getMessage(), e); log.info("business exceptionThe reason is{}", e.getMessage(), e);
return ApiResult.fail(e.getErrorCode(), e.getMessage()); return ApiResult.fail(e.getErrorCode(), e.getMessage());
} }
}
/**
* http请求方式不支持
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ApiResult<Void> handleException(HttpRequestMethodNotSupportedException e) {
log.error(e.getMessage(), e);
return ApiResult.fail(-1, String.format("不支持'%s'请求", e.getMethod()));
}
}