From 9c61f7c1a8ff44ccd6d3c55c13e724226fa7120a Mon Sep 17 00:00:00 2001 From: Guilhem BELLION Date: Wed, 15 Aug 2018 11:02:26 +0200 Subject: [PATCH] Use standard Promises instead of 'node-promise' module --- lib/close.io.js | 39 ++++++++++++++++++++------------------- package.json | 1 - 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/close.io.js b/lib/close.io.js index 85c3640..4fe93ec 100644 --- a/lib/close.io.js +++ b/lib/close.io.js @@ -1,5 +1,4 @@ 'use strict'; -var deferred = require('node-promise').defer; var request = require('request'); var qs = require('querystring'); @@ -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) { diff --git a/package.json b/package.json index 5a7dd4e..c174ee2 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "test": "./node_modules/mocha/bin/mocha --recursive test/" }, "dependencies": { - "node-promise": "0.5.8", "request": "2.69.0" }, "devDependencies": {