它不起作用,并且有相应的线程来处理它:
https://github.com/axios/axios/issues/647
所以,我尝试了以下代码:
let canceltoken=axios.canceltoken;
const source=cancelToken.source();
尝试{
让响应=空;
设置超时(()=>){
if(响应===空){
source.cancel();
}
},60*1500*1000);
response=wait axios.post('/gene_info',postdata,canceltoken:source.token);
console.log(响应);
}捕获(错误){
console.log(错误);
}
它也不起作用。请求超时,我会看到空响应错误,即使在node.jsbackend上,我也会看到结果正确返回。在后端,我正在向neo4j数据库发出一个非常长的运行请求。我怀疑它可能会超时,所以我添加到neo4j.config
文件以下行:
unsupported.dbms.executiontime_limit.enabled=true
不支持.dbms.executiontime_limit.time=9999999999999 s
我在这里找到的:
How to configure a query timeout in neo4j 3.0.1
重新启动,但也没有帮助。这是我在候机厅看到的:

我不确定这是什么post/gene_info--ms-意味着,无论问题是仍然在前端,还是后端,但我有一个怀疑,即neo4j
now times out,但它仍然在计算结果,我看到使用console.log()的结果。如有任何建议,我们将不胜感激。
更新
我尝试使用responses.fetch.,但仍然不起作用。代码如下:
fetchwithtimeout=(url,postdata,timeout)=>。{
设didtimeout=false;
新承诺(功能(解决、拒绝){
const timeout=设置超时(函数()。{
didTimeout=真;
拒绝(新错误(“请求超时”);
},超时);
获取(URL,,{
方法:“post”,
标题:{
“accept”:“应用程序/json”,
'content type':'application/json',
}
超时:超时,
正文:json.stringify(postdata)
})
.then(功能(响应){
//清除超时作为清除
ClearTimeout(超时);
如果(!)滴滴超时){
console.log('拿回好的!',响应);
解决(响应);
}
})
.catch(函数(err){
console.log('提取失败!',err);
//setTimeout已发生拒绝
如果(didtimeout)返回;
//错误拒绝
拒绝(err);
(});
})
.then(函数()。{
//请求成功,没有超时
console.log('承诺良好,没有超时!');
})
.catch(函数(err){
//错误:响应错误、请求超时或运行时错误
console.log('承诺错误!',err);
(});
}
然后我这样调用这个函数:
let postdata=“jsondata”:genenamearr,
“datasetname”:this.props.datasetname;
this.fetchwithTimeout('/gene_info',postdata,timeout).then((response)=>。{
console.log(“fetchWithTimeout完成!”);
console.log(响应);
(});
更新
我试过使用axios.create().function with no success:。
const axoisinstance=axois.create({
baseurl:'/gene_info',
超时:超时
(});
axoisinstance.post('',postdata).then((response)=>。{
console.log(“axios请求通过create()方法完成”);
console.log(响应);
(});
如果前端似乎没有任何工作,我会认为是来自neo4jdriver的超时,即使结果是以某种方式返回的。这是我用来给司机的代码:
router.post('/gene_info',function(req,res)'{
…
…
var驱动程序=dbutils.driver;
const session=driver.session();
会话.run(
完整查询,
{}
)然后(结果=>。{
const exprdata=chartService.PrepareGeneInfoData(结果“”);
研究JSON({
出口
(});
session.close();
(});
})
或者,它也可以是express.router();that I am using for treatinggetandpost.requests on the backend withnode.js.
它不起作用,并且有相应的线程来处理它:
https://github.com/axios/axios/issues/647
因此,我尝试了以下代码:
let CancelToken = axios.CancelToken;
const source = CancelToken.source();
try {
let response = null;
setTimeout(() => {
if (response === null) {
source.cancel();
}
}, 60 * 1500 * 1000);
response = await axios.post('/gene_info', postData, {cancelToken: source.token});
console.log(response);
} catch (error) {
console.log(error);
}
它也不起作用。请求超时,我看到空响应错误,即使在Node.js
后端我看到结果正确返回。在后端,我向Neo4j
数据库。我怀疑它可能会超时,所以我补充说neo4j.config
归档以下行:
unsupported.dbms.executiontime_limit.enabled=true
unsupported.dbms.executiontime_limit.time=99999999999999s
我在这里找到的:
How to configure a query timeout in Neo4j 3.0.1
重新启动neo4j
但也没有帮助。以下是我在航站楼看到的:

我不知道这是什么POST /gene_info - - ms - -
意思是,问题还是在前端,还是在后端,但我怀疑新4J
现在超时了,但它仍然在计算我看到使用的结果console.log()
声明。任何建议都将不胜感激。
更新
我试过用Reacts
fetch
,但仍然不起作用。代码如下:
fetchWithTimeout = (url, postData, timeout) => {
let didTimeOut = false;
new Promise(function(resolve, reject) {
const timeout = setTimeout(function() {
didTimeOut = true;
reject(new Error('Request timed out'));
}, timeout);
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
timeout: timeout,
body: JSON.stringify(postData)
})
.then(function(response) {
// Clear the timeout as cleanup
clearTimeout(timeout);
if(!didTimeOut) {
console.log('fetch good! ', response);
resolve(response);
}
})
.catch(function(err) {
console.log('fetch failed! ', err);
// Rejection already happened with setTimeout
if(didTimeOut) return;
// Reject with error
reject(err);
});
})
.then(function() {
// Request success and no timeout
console.log('good promise, no timeout! ');
})
.catch(function(err) {
// Error: response error, request timeout or runtime error
console.log('promise error! ', err);
});
}
然后我这样调用这个函数:
let postData = {"jsonData": geneNameArr,
"datasetName": this.props.datasetName};
this.fetchWithTimeout('/gene_info', postData, timeout).then((response) => {
console.log("fetchWithTimeout is done!");
console.log(response);
});
更新
我试过用axios.create()
功能未成功:
const axiosInstance = axios.create({
baseURL: '/gene_info',
timeout: timeout
});
axiosInstance.post('', postData).then((response) => {
console.log("axios request is done with create() method");
console.log(response);
});
如果前端没有任何工作,我会认为是来自新4J
驱动程序,即使以某种方式返回结果。这是我为司机使用的代码:
router.post('/gene_info', function(req, res) {
...
...
var driver = dbUtils.driver;
const session = driver.session();
session.run(
full_query,
{}
).then(result => {
const exprData = chartService.prepareGeneInfoData(result, '');
res.json({
exprData
});
session.close();
});
})
或者也可能是express.Router();
我用来治疗的get
和post
后端请求节点.js