Reduced method complexity for sendTestEmail method
refs baccbb4942
refs https://github.com/TryGhost/Team/issues/694
- The change is here to remove yet another ESLint method complexity error
- The custom error handling complexity was introduced here in a referenced commit without an obvious reason. The specifics of how the "sendTestEmail" method handles errors should not leak out from the method, if there are errors in the response they should be handled internally and the method would uniformly reject with a single error.
This commit is contained in:
parent
807322dccb
commit
26f419f085
@ -59,21 +59,15 @@ module.exports = {
|
||||
async query(frame) {
|
||||
const options = Object.assign(frame.options, {status: 'all'});
|
||||
let model = await models.Post.findOne(options, {withRelated: ['authors']});
|
||||
|
||||
if (!model) {
|
||||
throw new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.posts.postNotFound')
|
||||
});
|
||||
}
|
||||
|
||||
const {emails = [], memberSegment} = frame.data;
|
||||
const response = await mega.mega.sendTestEmail(model, emails, 'canary', memberSegment);
|
||||
if (response && response[0] && response[0].error) {
|
||||
throw new errors.EmailError({
|
||||
statusCode: response[0].error.statusCode,
|
||||
message: response[0].error.message,
|
||||
context: response[0].error.originalMessage
|
||||
});
|
||||
}
|
||||
return response;
|
||||
return await mega.mega.sendTestEmail(model, emails, 'canary', memberSegment);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -56,21 +56,15 @@ module.exports = {
|
||||
async query(frame) {
|
||||
const options = Object.assign(frame.options, {status: 'all'});
|
||||
let model = await models.Post.findOne(options, {withRelated: ['authors']});
|
||||
|
||||
if (!model) {
|
||||
throw new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.posts.postNotFound')
|
||||
});
|
||||
}
|
||||
|
||||
const {emails = []} = frame.data;
|
||||
const response = await mega.mega.sendTestEmail(model, emails, 'v3');
|
||||
if (response && response[0] && response[0].error) {
|
||||
throw new errors.EmailError({
|
||||
statusCode: response[0].error.statusCode,
|
||||
message: response[0].error.message,
|
||||
context: response[0].error.originalMessage
|
||||
});
|
||||
}
|
||||
return response;
|
||||
return await mega.mega.sendTestEmail(model, emails, 'v3');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -109,6 +109,14 @@ const sendTestEmail = async (postModel, toEmails, apiVersion, memberSegment) =>
|
||||
return Promise.reject(response.error);
|
||||
}
|
||||
|
||||
if (response && response[0] && response[0].error) {
|
||||
return Promise.reject(new errors.EmailError({
|
||||
statusCode: response[0].error.statusCode,
|
||||
message: response[0].error.message,
|
||||
context: response[0].error.originalMessage
|
||||
}));
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user