mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
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
This commit is contained in:
parent
294f3769cb
commit
edca4138ff
3 changed files with 19 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue