I am trying to set the timeout values inside request module of node.js but as per the given time its not returning the response. I am explaining my code below.
postRequestOptions.url = `${nsoObj.protocol}://${nsoObj.ipAddress}:${nsoObj.httpPortNbr}/jsonrpc`;
postRequestOptions.headers = {
'Content-Type': 'application/json'
};
postRequestOptions.body = {
jsonrpc: '2.0',
id: 1,
method: 'login',
timeout: 5000,
params: {
user: nsoObj.userName,
passwd: nsoObj.password
}
};
request(postRequestOptions, (error, response, loginResponse) => {
console.log('\n error: ', error);
console.log('\n loginResponse: ', loginResponse);
if (error || !loginResponse.id) {
responseObj = {
status : 'error',
msg : `Error occurred while performing Login into "${nsoObj.nsoNickName}" Instance. ${error}`,
body : null
};
reject(responseObj);
} else {
loginResponse.sessionId = response.headers['set-cookie'][0];
responseObj = {
status : 'success',
msg : `Successfully performing Login into "${nsoObj.nsoNickName}" Instance`,
body : loginResponse
};
resolve(responseObj);
}
});
});
Here I am using request module of node.js and set timeout of 5ms. But When I am running this its taking 2min to sent back the timeout error response.
Here I need if this request could not sent back the response within 5 milisecond then it should return the timeout error.