我正在使用请求承诺将数据获取/发布到API。使用Interval来访问API URL。 间隔设置为30秒。有时它会在请求时出现EBUSY错误。
代码:-
const request = require("request-promise");
function getToken(username,password,endpoint) {
return request({
url : endpoint + "/oauth/token",method : "POST",auth : { user: username,pass: password },headers: { "Content-Type": "application/x-www-form-urlencoded" },form : { type: "client_credentials" }
})
.then(function (result) {
return result;
})
.catch(function (error) {
// ... error checks
console.log(error);
throw error;
});
}
错误:-
Error: getaddrinfo EBUSY xxxx.xxxx.com\n at new RequestError (/home/node_modules/request-promise-core/lib/errors.js:14:15)\n at Request.plumbing.callback (/home/node_modules/request-promise-core/lib/plumbing.js:87:29)\n at Request.RP$callback [as _callback] (/home/node_modules/request-promise-core/lib/plumbing.js:46:31)\n at self.callback (/home/node_modules/request/request.js:185:22)\n at Request.emit (events.js:203:13)\n at
at Request.onRequestError (/home/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:203:13)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:6571) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6571) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我也正在使用try {} catch(e){},但它仍然打破了间隔。
每次停止后,我们都必须在服务器上手动执行它。