From 557f50be7ee645082435f271e52230cd677fa39c Mon Sep 17 00:00:00 2001 From: superKalo Date: Fri, 24 Nov 2017 01:14:31 +0200 Subject: [PATCH 1/3] Add: simple test to see if the promise is rejected --- test/data-management.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/data-management.js b/test/data-management.js index 4d18cfa..cbf908e 100644 --- a/test/data-management.js +++ b/test/data-management.js @@ -165,4 +165,20 @@ describe('Data Management', () => { }); }); }); + + it('Should reject the promise', done => { + const repo = new SuperRepo({ + storage: 'LOCAL_VARIABLE', + name: 'test', + outOfDateAfter: 0, + request: () => { + return new Promise((resolve, reject) => reject('whatever')); + } + }); + + repo.getData() + .catch( () => { + expect(true).to.equal(true); + }).then(done, done); + }); }); From 417ab50ff74d4191fcf99adb83c36c15b69d8678 Mon Sep 17 00:00:00 2001 From: superKalo Date: Fri, 24 Nov 2017 01:14:42 +0200 Subject: [PATCH 2/3] Fix: handle promise rejection --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index b287bf9..4288753 100644 --- a/src/index.js +++ b/src/index.js @@ -366,7 +366,7 @@ class SuperRepo { */ this.isPromisePending = true; - return this.promise = new Promise(_resolve => { + return this.promise = new Promise((_resolve, _reject) => { this.getDataUpToDateStatus().then(_res => { if (_res.isDataUpToDate) { @@ -382,7 +382,8 @@ class SuperRepo { return _response; }) - .then(_resolve); + .then(_resolve) + .catch(_reject); } }); @@ -416,7 +417,7 @@ class SuperRepo { const { outOfDateAfter } = this.config; return new Promise(_resolve => { - this.getDataUpToDateStatus().then(_res => { + this.getDataUpToDateStatus().then((_res, _rej) => { /** * If data is up to date, determine when it gets outdated. From 1fadd8135823e84c29f1c0c595a71425c8574385 Mon Sep 17 00:00:00 2001 From: superKalo Date: Tue, 16 Jan 2018 21:24:46 +0200 Subject: [PATCH 3/3] Add: production build --- lib/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 6bb9c9b..a744224 100644 --- a/lib/index.js +++ b/lib/index.js @@ -464,7 +464,7 @@ var SuperRepo = function () { */ this.isPromisePending = true; - return this.promise = new Promise(function (_resolve) { + return this.promise = new Promise(function (_resolve, _reject) { _this10.getDataUpToDateStatus().then(function (_res) { if (_res.isDataUpToDate) { @@ -478,7 +478,7 @@ var SuperRepo = function () { _this10.isPromisePending = false; return _response; - }).then(_resolve); + }).then(_resolve).catch(_reject); } }); }); @@ -522,7 +522,7 @@ var SuperRepo = function () { return new Promise(function (_resolve) { - _this12.getDataUpToDateStatus().then(function (_res) { + _this12.getDataUpToDateStatus().then(function (_res, _rej) { /** * If data is up to date, determine when it gets outdated.