处理全局异常 NoResourceFoundException

This commit is contained in:
lin 2026-06-25 16:26:22 +08:00
parent cf5bcb6349
commit c73d6a1b27

View File

@ -11,6 +11,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;
/**
* 全局异常处理
@ -31,6 +32,17 @@ public class GlobalExceptionHandler {
return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage());
}
/**
* 默认异常处理
* @param e 异常
* @return 统一返回结果
*/
@ExceptionHandler(NoResourceFoundException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public WVPResult<String> exceptionHandler(NoResourceFoundException e) {
return WVPResult.fail(ErrorCode.ERROR404);
}
/**
* 默认异常处理
* @param e 异常