Skip to content

Commit 2331c2a

Browse files
authored
fix(core): Improve hook missing parameter message by adding the service name (#1703)
1 parent 5f21272 commit 2331c2a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

packages/feathers/lib/hooks/base.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ const assignArguments = context => {
1616
};
1717

1818
const validate = context => {
19-
const { service, method } = context;
19+
const { service, method, path } = context;
2020
const parameters = service.methods[method];
2121

2222
if (parameters.includes('id') && context.id === undefined) {
23-
throw new Error(`An id must be provided to the '${method}' method`);
23+
throw new Error(`An id must be provided to the '${path}.${method}' method`);
2424
}
2525

2626
if (parameters.includes('data') && !_.isObjectOrArray(context.data)) {
27-
throw new Error(`A data object must be provided to the '${method}' method`);
27+
throw new Error(`A data object must be provided to the '${path}.${method}' method`);
2828
}
2929

3030
return context;

packages/feathers/test/hooks/hooks.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ describe('hooks basics', () => {
1818

1919
return app.service('dummy').get();
2020
}).catch(e => {
21-
assert.strictEqual(e.message, `An id must be provided to the 'get' method`);
21+
assert.strictEqual(e.message, `An id must be provided to the 'dummy.get' method`);
2222
}).then(() =>
2323
app.service('dummy').create()
2424
).catch(e => {
25-
assert.strictEqual(e.message, `A data object must be provided to the 'create' method`);
25+
assert.strictEqual(e.message, `A data object must be provided to the 'dummy.create' method`);
2626
});
2727
});
2828

@@ -201,7 +201,7 @@ describe('hooks basics', () => {
201201
assert.strictEqual(context.service, app.service('dummy'));
202202
assert.strictEqual(context.type, 'error');
203203
assert.strictEqual(context.path, 'dummy');
204-
assert.strictEqual(context.error.message, 'An id must be provided to the \'get\' method');
204+
assert.strictEqual(context.error.message, 'An id must be provided to the \'dummy.get\' method');
205205
});
206206
});
207207

packages/rest-client/test/index.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ describe('REST client tests', function () {
7979
const service = app.service('todos');
8080

8181
return service.get().catch(error => {
82-
assert.strictEqual(error.message, `An id must be provided to the 'get' method`);
82+
assert.strictEqual(error.message, `An id must be provided to the 'todos.get' method`);
8383

8484
return service.remove();
8585
}).catch(error => {
86-
assert.strictEqual(error.message, `An id must be provided to the 'remove' method`);
86+
assert.strictEqual(error.message, `An id must be provided to the 'todos.remove' method`);
8787

8888
return service.update();
8989
}).catch(error => {
90-
assert.strictEqual(error.message, `An id must be provided to the 'update' method`);
90+
assert.strictEqual(error.message, `An id must be provided to the 'todos.update' method`);
9191

9292
return service.patch();
9393
}).catch(error => {
94-
assert.strictEqual(error.message, `An id must be provided to the 'patch' method`);
94+
assert.strictEqual(error.message, `An id must be provided to the 'todos.patch' method`);
9595
});
9696
});
9797
});

0 commit comments

Comments
 (0)