Skip to content

Commit

Permalink
Merge pull request #11 from contentking/missing-parameters-more-verbose
Browse files Browse the repository at this point in the history
Improved error message on "missing parameters"
  • Loading branch information
troch authored Nov 7, 2017
2 parents 3801711 + b562e5c commit 144d0bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion modules/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ export default class Path {
);

// Check all params are provided (not search parameters which are optional)
if (this.urlParams.some(p => !exists(encodedParams[p]))) throw new Error('Missing parameters');
if (this.urlParams.some(p => !exists(encodedParams[p]))) {
const missingParameters = this.urlParams.filter(p => !exists(encodedParams[p]));
throw new Error('Cannot build path: \'' + this.path + '\' requires missing parameters { ' + missingParameters.join(', ') + ' }');
}

// Check constraints
if (!options.ignoreConstraints) {
Expand Down
2 changes: 1 addition & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Path', function () {
path.build({ id: '123', id2: 'abc' }).should.equal('/users/profile/123-abc.html');
(function () {
path.build({ id: '123'});
}).should.throw('Missing parameters');
}).should.throw('Cannot build path: \'/users/profile/:id-:id2.html\' requires missing parameters { id2 }');
});

it('should match and build paths with query parameters', function () {
Expand Down

0 comments on commit 144d0bf

Please sign in to comment.