Skip to content

Commit

Permalink
Use standard Promises instead of 'node-promise' module
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhembellion committed Aug 15, 2018
1 parent 3fc717f commit 9c61f7c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
39 changes: 20 additions & 19 deletions lib/close.io.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
var deferred = require('node-promise').defer;
var request = require('request');
var qs = require('querystring');

Expand Down Expand Up @@ -235,25 +234,27 @@ Closeio.prototype._request = function(options) {
pass: ''
};
options.jar = false;
var d = deferred();
request(options, function(error, response, body) {
if (!error && response.statusCode === 200) {
d.resolve(JSON.parse(body));
return;
}
if (error) {
d.reject(error);
return;
}
var rejection;
try {
rejection = JSON.parse(body);
}catch(e){
rejection = response.statusCode == 200 ? body : response.statusCode;
}
d.reject(rejection);
return new Promise((resolve, reject) => {
request(options, function(error, response, body) {
if (!error && response.statusCode === 200) {
resolve(JSON.parse(body));
return;
}
if (error) {
reject(error);
return;
}
var rejection;
try {
rejection = JSON.parse(body);
}catch(e){
rejection = response.statusCode == 200 ? body : response.statusCode;
}
const err = new Error();
err.data = rejection;
reject(err);
});
});
return d.promise;
};

Closeio.prototype._post = function(path, options) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"test": "./node_modules/mocha/bin/mocha --recursive test/"
},
"dependencies": {
"node-promise": "0.5.8",
"request": "2.69.0"
},
"devDependencies": {
Expand Down

0 comments on commit 9c61f7c

Please sign in to comment.