在我的React应用程序中,我使用fetch()
从我的API中获取数据,_callAPI()
函数获取domain
参数,如果我的数据库中存在该域的网站,则调用API。如果存在,则返回网站的对象,否则返回500。因此,在我使用fetch()之前,我无法判断该网站是否存在。问题是,每次fetch()没有找到任何东西时,它会抛出以下代码:
container.jsx:25 GET http://localhost:3000/boutiques/detail/?q=testdomain.com 500 (内部服务器错误)
当它找不到很多网站时,控制台日志中就会填满该错误消息。有没有一种方法可以在获取时忽略这种消息?
fetch()
_callApi = () => {
const { domain } = this.props;
return fetch(`/boutiques/detail/?q=${domain}`)
.then(response => {
if (response.status === 500) {
return 500;
}
return response.json();
})
.then(json => json)
.catch(err => console.log(err));
};
https://stackoverflow.com/questions/52807184
复制相似问题