
Node.js
1
Вклад в тег
function handleBody(body){
console.log(body);
...
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
handleBody(body);
}
});
function myRequest(options){
return new Promise(function(resolve,reject){
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
return resolve(body)
}
//@todo handle errors
reject()
});
});
}
myRequest(options).then(function(body){
//тут теперь продолжается работа с body
}).catch(function(err){
//code
})