我正在从客户端进行API调用,但是等待4分钟后它失败了。
但是,当我在Oracle SQL Developer中运行相同的查询时,虽然花费了相同的时间,但是却在那里显示了数据。
我在前端使用 ReactJS ,在后端使用 nodeJS 。
任何人都可以告诉我前端应该更改什么,以便API调用不会失败并可以呈现数据。
在邮递员中,它还会引发错误-等待很长时间后无法获得响应。
componentDidMount() {
// debugger;
// event.preventDefault();
axios.get(`http://localhost:4000/api/AMS/country`)
.then(response => {
// console.log(response);
const country_Claim_Type = response.data;
this.setState({ country_Claim_Type
});
console.log('data fetched');
return axios.get(`http://localhost:4000/api/AMS/countryDollar`)
}).then(response => {
// console.log(response);
const country_Claim_Dollar = response.data;
this.setState({ country_Claim_Dollar
});
console.log('data fetched');
return axios.get(`http://localhost:4000/api/AMS/claimQuarter`)
}).then(res => {
const claims = res.data;
let claim = [];
let puru = [];
claims.forEach(element => {
claim.push(element.COUNT);
puru.push(element.USD);
});
this.setState({
Data: {
labels: ['FY19 Q1[NOV-JAN]','FY19 Q2[FEB-APR]','FY18[SEP-NOV]'],
datasets:[
{
label:'',
data: claim ,puru,
backgroundColor:[
'rgba(255,105,145,0.6)',
'rgba(155,100,210,0.6)',
'rgb(63, 191, 191)'
]
}
]
}
});
return axios.get(`http://localhost:4000/api/AMS/claimType`)
}) .then(barGraph => {
const claims = barGraph.data;
let claimcount = [];
let claimtype = [];
claims.forEach(element => {
claimcount.push(element.COUNT);
claimtype.push(element.CLT_NAME);
});
this.setState({
Claim_Type: {
labels: claimtype,
datasets:[
{
label:'',
data: claimcount ,
backgroundColor:[
'rgba(255,105,145,0.6)',
'rgba(155,100,210,0.6)',
'rgb(255, 0, 64)',
'rgb(191, 255, 0)',
'rgb(0, 255, 255)',
'rgb(128, 0, 255)'
]
}
]
}
});
return axios.get(`http://localhost:4000/api/AMS/claimCountry`)
}).then(countryList => {
const claims = countryList.data;
let claimcount = [];
let country = [];
var coloR = [];
const percent = "%";
// let claimvalue = [];
let claimTotal = 0;
var dynamicColors = function() {
var r = Math.floor(Math.random() * 255);
var g = Math.floor(Math.random() * 255);
var b = Math.floor(Math.random() * 255);
return "rgb(" + r + "," + g + "," + b + ")";
};
claims.forEach(element => {
claimTotal+=element.COUNT;
});
claims.forEach(element => {
claimcount.push(parseFloat((element.COUNT/claimTotal)*100).toFixed(2));
// claimvalue.push(element.USD);
country.push(element.COUNTRY);
coloR.push(dynamicColors());
});
this.setState({
country_claim: {
labels: country,
datasets:[
{
label:'ClaimCounts',
data: claimcount,
backgroundColor: coloR
}
]
}
});
return axios.get(`http://localhost:4000/api/AMS/claimDollar`)
}).then(res => {
const claims = res.data;
let dollar = [];
claims.forEach(element => {
dollar.push(element.USD);
});
this.setState({
dollar_value: {
labels: ['Q1','Q2','FY18'],
datasets:[
{
label:'',
data: dollar ,
backgroundColor:[
'rgba(255,105,145,0.6)',
'rgba(155,100,210,0.6)',
'rgb(63, 191, 191)'
]
}
]
}
});
})
}
答案 0 :(得分:0)
如果您的数据库连接正确,并且获取数据花了很长时间,则会导致超时错误。您只需要增加您的请求超时时间,具体来说就是这样:
req.setTimeout(5 * 60 * 1000);