From b93187b0f99343f012f2252f7f54006b4d62f61f Mon Sep 17 00:00:00 2001 From: Sujesh T Date: Sat, 30 Nov 2019 17:21:25 +0530 Subject: [PATCH] feat: change hasone relation error message The current hasone error message is not appropriate one. So adds a better message. --- lib/model.js | 4 +++- test/relations.integration.js | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/model.js b/lib/model.js index 20c3aed2..e24545a9 100644 --- a/lib/model.js +++ b/lib/model.js @@ -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'; diff --git a/test/relations.integration.js b/test/relations.integration.js index 234e0a5f..78805657 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -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); }); });