Skip to content

Commit

Permalink
Include missing paths in MaxRetryExceededError instances
Browse files Browse the repository at this point in the history
this will help developers understand data source and service failures better
  • Loading branch information
asyncanup committed Sep 8, 2017
1 parent 596ca02 commit 01198ad
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/errors/MaxRetryExceededError.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ var NAME = "MaxRetryExceededError";
*
* @private
*/
function MaxRetryExceededError() {
function MaxRetryExceededError(missingPaths) {
this.message = "The allowed number of retries have been exceeded.";
this.missingPaths = missingPaths || [];
this.stack = (new Error()).stack;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/response/get/getRequestCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function getRequestCycle(getResponse, model, results, observer,
errors, count) {
// we have exceeded the maximum retry limit.
if (count === model._maxRetries) {
observer.onError(new MaxRetryExceededError());
observer.onError(new MaxRetryExceededError(results.requestedMissingPaths));
return {
dispose: function() {}
};
Expand Down
9 changes: 5 additions & 4 deletions lib/response/set/setRequestCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ var MaxRetryExceededError = require("./../../errors/MaxRetryExceededError");
*/
module.exports = function setRequestCycle(model, observer, groups,
isJSONGraph, isProgressive, count) {
var requestedAndOptimizedPaths = setGroupsIntoCache(model, groups);
var optimizedPaths = requestedAndOptimizedPaths.optimizedPaths;
var requestedPaths = requestedAndOptimizedPaths.requestedPaths;

// we have exceeded the maximum retry limit.
if (count === model._maxRetries) {
observer.onError(new MaxRetryExceededError());
observer.onError(new MaxRetryExceededError(requestedPaths));
return {
dispose: function() {}
};
}

var requestedAndOptimizedPaths = setGroupsIntoCache(model, groups);
var optimizedPaths = requestedAndOptimizedPaths.optimizedPaths;
var requestedPaths = requestedAndOptimizedPaths.requestedPaths;
var isMaster = model._source === undefined;

// Local set only. We perform a follow up get. If performance is ever
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"license": "Apache-2.0",
"scripts": {
"test": "gulp test-coverage",
"test:only": "mocha test/index.js",
"dist": "gulp all",
"doc": "gulp doc",
"perf": "gulp perf-run",
Expand Down
18 changes: 17 additions & 1 deletion test/falcor/get/get.dataSource-only.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,24 @@ describe('DataSource Only', function() {
return done();
}, done.bind('should not complete'));
});

it('should return missing paths with MaxRetryExceededError', function(done) {
var model = new Model({ source: asyncifyDataSource(new LocalDataSource({})) });
toObservable(model.
get(['videos', 0, 'title'], 'hall[0].ween')).
doAction(noOp, function(e) {
expect(MaxRetryExceededError.is(e), 'MaxRetryExceededError expected.').to.be.ok;
expect(e.missingPaths).to.deep.equals([['videos', 0, 'title'], ['hall', 0, 'ween']]);
}).
subscribe(noOp, function(e) {
if (isAssertionError(e)) {
return done(e);
}
return done();
}, done.bind('should not complete'));
});
});

function isAssertionError(e) {
return e.hasOwnProperty('expected') && e.hasOwnProperty('actual');
}
}

0 comments on commit 01198ad

Please sign in to comment.