Skip to content

Commit

Permalink
Merge pull request #14 from superKalo/config/handle-promise-rejections
Browse files Browse the repository at this point in the history
Bug / Handle Promise Rejection
  • Loading branch information
superKalo authored Jan 16, 2018
2 parents 935b6fd + 1fadd81 commit a8a6914
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -478,7 +478,7 @@ var SuperRepo = function () {
_this10.isPromisePending = false;

return _response;
}).then(_resolve);
}).then(_resolve).catch(_reject);
}
});
});
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -382,7 +382,8 @@ class SuperRepo {

return _response;
})
.then(_resolve);
.then(_resolve)
.catch(_reject);
}
});

Expand Down Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions test/data-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit a8a6914

Please sign in to comment.