Skip to content

Commit

Permalink
feat: change hasone relation error message
Browse files Browse the repository at this point in the history
The current hasone error message is not appropriate one.
So adds a better message.
  • Loading branch information
sujeshthekkepatt committed Dec 2, 2019
1 parent ec1d4ce commit d83b74e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@ module.exports = function(registry) {
if (ctx.result !== null) return cb();

const fk = ctx.getArgByName('fk');
const msg = g.f('Unknown "%s" id "%s".', toModelName, fk);
const msg = fk ?
g.f('Unknown "%s" id "%s".', toModelName, fk) :
g.f('No "%s" instance(s) found', toModelName);
const error = new Error(msg);
error.statusCode = error.status = 404;
error.code = 'MODEL_NOT_FOUND';
Expand Down
5 changes: 5 additions & 0 deletions test/relations.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,11 @@ describe('relations - integration', function() {
const url = '/api/customers/' + cust.id + '/profile';
this.get(url)
.expect(404, function(err, res) {
const expected = 'No "profile" instance(s) found';
expect(res.body.error.message).to.be.equal(
expected,
);
expect(res.body.error.code).to.be.equal('MODEL_NOT_FOUND');
done(err);
});
});
Expand Down

0 comments on commit d83b74e

Please sign in to comment.