Skip to content

Commit

Permalink
feat: provide more details in "Missing parameters" error [router5/rou…
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtech-dobes committed Nov 7, 2017
1 parent 3801711 commit b562e5c
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 b562e5c

Please sign in to comment.