Commit 7038be6d by weisong

add method not support error

parent 2fedd938
......@@ -4,6 +4,7 @@ import com.cnooc.expert.common.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.RestControllerAdvice;
......@@ -59,6 +60,18 @@ public class GlobalExceptionHandler {
return ApiResult.error(GlobalErrorCodeConstants.SYSTEM_ERROR.getCode(), GlobalErrorCodeConstants.SYSTEM_ERROR.getMsg());
}
/**
* 处理 HTTP 方法不支持异常
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ApiResult<String> handleHttpRequestMethodNotSupportedException(
HttpRequestMethodNotSupportedException e, HttpServletRequest request) {
log.warn("HTTP方法不支持: {},请求URL: {}", e.getMessage(), request.getRequestURI());
return ApiResult.error(HttpStatus.METHOD_NOT_ALLOWED.value(),
"不支持 " + e.getMethod() + " 请求方法 ");
}
@ExceptionHandler(Exception.class)
public ApiResult<String> handleException(Exception e, HttpServletRequest request) {
log.error("系统异常: {},请求URL: {}", e.getMessage(), request.getRequestURI(), e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment