From 2331c2a3dd70d432db7d62a76ed805d359cbbba5 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Tue, 26 Nov 2019 12:33:19 -0800 Subject: [PATCH] fix(core): Improve hook missing parameter message by adding the service name (#1703) --- packages/feathers/lib/hooks/base.js | 6 +++--- packages/feathers/test/hooks/hooks.test.js | 6 +++--- packages/rest-client/test/index.test.js | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/feathers/lib/hooks/base.js b/packages/feathers/lib/hooks/base.js index b044ea7983..bde4fea210 100644 --- a/packages/feathers/lib/hooks/base.js +++ b/packages/feathers/lib/hooks/base.js @@ -16,15 +16,15 @@ const assignArguments = context => { }; const validate = context => { - const { service, method } = context; + const { service, method, path } = context; const parameters = service.methods[method]; if (parameters.includes('id') && context.id === undefined) { - throw new Error(`An id must be provided to the '${method}' method`); + throw new Error(`An id must be provided to the '${path}.${method}' method`); } if (parameters.includes('data') && !_.isObjectOrArray(context.data)) { - throw new Error(`A data object must be provided to the '${method}' method`); + throw new Error(`A data object must be provided to the '${path}.${method}' method`); } return context; diff --git a/packages/feathers/test/hooks/hooks.test.js b/packages/feathers/test/hooks/hooks.test.js index 020fbf25b4..efe184c633 100644 --- a/packages/feathers/test/hooks/hooks.test.js +++ b/packages/feathers/test/hooks/hooks.test.js @@ -18,11 +18,11 @@ describe('hooks basics', () => { return app.service('dummy').get(); }).catch(e => { - assert.strictEqual(e.message, `An id must be provided to the 'get' method`); + assert.strictEqual(e.message, `An id must be provided to the 'dummy.get' method`); }).then(() => app.service('dummy').create() ).catch(e => { - assert.strictEqual(e.message, `A data object must be provided to the 'create' method`); + assert.strictEqual(e.message, `A data object must be provided to the 'dummy.create' method`); }); }); @@ -201,7 +201,7 @@ describe('hooks basics', () => { assert.strictEqual(context.service, app.service('dummy')); assert.strictEqual(context.type, 'error'); assert.strictEqual(context.path, 'dummy'); - assert.strictEqual(context.error.message, 'An id must be provided to the \'get\' method'); + assert.strictEqual(context.error.message, 'An id must be provided to the \'dummy.get\' method'); }); }); diff --git a/packages/rest-client/test/index.test.js b/packages/rest-client/test/index.test.js index 41c287f7c7..dd4eb06a2d 100644 --- a/packages/rest-client/test/index.test.js +++ b/packages/rest-client/test/index.test.js @@ -79,19 +79,19 @@ describe('REST client tests', function () { const service = app.service('todos'); return service.get().catch(error => { - assert.strictEqual(error.message, `An id must be provided to the 'get' method`); + assert.strictEqual(error.message, `An id must be provided to the 'todos.get' method`); return service.remove(); }).catch(error => { - assert.strictEqual(error.message, `An id must be provided to the 'remove' method`); + assert.strictEqual(error.message, `An id must be provided to the 'todos.remove' method`); return service.update(); }).catch(error => { - assert.strictEqual(error.message, `An id must be provided to the 'update' method`); + assert.strictEqual(error.message, `An id must be provided to the 'todos.update' method`); return service.patch(); }).catch(error => { - assert.strictEqual(error.message, `An id must be provided to the 'patch' method`); + assert.strictEqual(error.message, `An id must be provided to the 'todos.patch' method`); }); }); });