diff --git a/modules/Path.js b/modules/Path.js index cc81c4f..9d55110 100644 --- a/modules/Path.js +++ b/modules/Path.js @@ -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) { diff --git a/test/main.js b/test/main.js index 5c0f41f..98bbd10 100644 --- a/test/main.js +++ b/test/main.js @@ -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 () {