feat: 优化404错误返回
This commit is contained in:
parent
67623100b0
commit
d679fd47bd
|
|
@ -17,6 +17,7 @@ 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;
|
||||
import org.springframework.web.servlet.resource.NoResourceFoundException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -66,4 +67,11 @@ public class GlobalRestControllerAdvice {
|
|||
public String handleNotLoginException(NotLoginException e) {
|
||||
return "请重新登录";
|
||||
}
|
||||
|
||||
@ExceptionHandler(NoResourceFoundException.class)
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
public ApiResult<Void> handleNoResourceFoundException(NoResourceFoundException ex) {
|
||||
log.error("请求的地址无效: ", ex);
|
||||
return ApiResult.error(STATE.BusinessError, "请求的地址无效:" + ex.getResourcePath());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue