From edca4138ff9f5323e1f58635ab5cd99a2217906a Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Tue, 3 Sep 2019 12:10:32 +0800 Subject: [PATCH] Updated getMember to return null rather than throw no-issue This allows members code to remove try/catch statements without having to pass the Ghost/bookshelf specific `require: false` option --- core/server/api/canary/members.js | 11 +++++++++-- core/server/api/v2/members.js | 11 +++++++++-- core/server/services/members/api.js | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/server/api/canary/members.js b/core/server/api/canary/members.js index 7a16817aa0..bb3a42968e 100644 --- a/core/server/api/canary/members.js +++ b/core/server/api/canary/members.js @@ -1,6 +1,7 @@ // NOTE: We must not cache references to membersService.api // as it is a getter and may change during runtime. const membersService = require('../../services/members'); +const common = require('../../lib/common'); const members = { docName: 'members', @@ -28,8 +29,14 @@ const members = { ], validation: {}, permissions: true, - query(frame) { - return membersService.api.members.get(frame.data, frame.options); + async query(frame) { + const member = await membersService.api.members.get(frame.data, frame.options); + if (!member) { + throw new common.errors.NotFoundError({ + message: common.i18n.t('errors.api.members.memberNotFound') + }); + } + return member; } }, diff --git a/core/server/api/v2/members.js b/core/server/api/v2/members.js index 7a16817aa0..bb3a42968e 100644 --- a/core/server/api/v2/members.js +++ b/core/server/api/v2/members.js @@ -1,6 +1,7 @@ // NOTE: We must not cache references to membersService.api // as it is a getter and may change during runtime. const membersService = require('../../services/members'); +const common = require('../../lib/common'); const members = { docName: 'members', @@ -28,8 +29,14 @@ const members = { ], validation: {}, permissions: true, - query(frame) { - return membersService.api.members.get(frame.data, frame.options); + async query(frame) { + const member = await membersService.api.members.get(frame.data, frame.options); + if (!member) { + throw new common.errors.NotFoundError({ + message: common.i18n.t('errors.api.members.memberNotFound') + }); + } + return member; } }, diff --git a/core/server/services/members/api.js b/core/server/services/members/api.js index fc47603d46..69dd00147d 100644 --- a/core/server/services/members/api.js +++ b/core/server/services/members/api.js @@ -29,7 +29,7 @@ function updateMember(member, newData) { } function getMember(data, options = {}) { - return models.Member.findOne(data, Object.assign({require: true}, options)).then((model) => { + return models.Member.findOne(data, options).then((model) => { if (!model) { return null; }