mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Fixed 500 error when deleting items that don't exist
fixes #11723 - when deleting an invite/label/tag/webhook that doesn't exist, Ghost would throw a 500 error - this commit catches the NotFoundError - also rejects from model if nothing was found - spotted in Sentry
This commit is contained in:
parent
946f7b872f
commit
a769bbe86c
9 changed files with 60 additions and 7 deletions
|
@ -77,7 +77,12 @@ module.exports = {
|
|||
frame.options.require = true;
|
||||
|
||||
return models.Invite.destroy(frame.options)
|
||||
.then(() => null);
|
||||
.then(() => null)
|
||||
.catch(models.Invite.NotFoundError, () => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.invites.inviteNotFound')
|
||||
}));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -139,7 +139,13 @@ module.exports = {
|
|||
},
|
||||
permissions: true,
|
||||
query(frame) {
|
||||
return models.Label.destroy(frame.options).then(() => null);
|
||||
return models.Label.destroy(frame.options)
|
||||
.then(() => null)
|
||||
.catch(models.Label.NotFoundError, () => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.labels.labelNotFound')
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -142,7 +142,13 @@ module.exports = {
|
|||
},
|
||||
permissions: true,
|
||||
query(frame) {
|
||||
return models.Tag.destroy(frame.options).then(() => null);
|
||||
return models.Tag.destroy(frame.options)
|
||||
.then(() => null)
|
||||
.catch(models.Tag.NotFoundError, () => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.tags.tagNotFound')
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -84,7 +84,16 @@ module.exports = {
|
|||
permissions: true,
|
||||
query(frame) {
|
||||
frame.options.require = true;
|
||||
return models.Webhook.destroy(frame.options).then(() => null);
|
||||
|
||||
return models.Webhook.destroy(frame.options)
|
||||
.then(() => null)
|
||||
.catch(models.Webhook.NotFoundError, () => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.resource.resourceNotFound', {
|
||||
resource: 'Webhook'
|
||||
})
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -77,7 +77,12 @@ module.exports = {
|
|||
frame.options.require = true;
|
||||
|
||||
return models.Invite.destroy(frame.options)
|
||||
.then(() => null);
|
||||
.then(() => null)
|
||||
.catch(models.Invite.NotFoundError, () => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.invites.inviteNotFound')
|
||||
}));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -142,7 +142,13 @@ module.exports = {
|
|||
},
|
||||
permissions: true,
|
||||
query(frame) {
|
||||
return models.Tag.destroy(frame.options).then(() => null);
|
||||
return models.Tag.destroy(frame.options)
|
||||
.then(() => null)
|
||||
.catch(models.Tag.NotFoundError, () => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.tags.tagNotFound')
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -84,7 +84,15 @@ module.exports = {
|
|||
permissions: true,
|
||||
query(frame) {
|
||||
frame.options.require = true;
|
||||
return models.Webhook.destroy(frame.options).then(() => null);
|
||||
return models.Webhook.destroy(frame.options)
|
||||
.then(() => null)
|
||||
.catch(models.Webhook.NotFoundError, () => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.resource.resourceNotFound', {
|
||||
resource: 'Webhook'
|
||||
})
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -107,6 +107,10 @@ Label = ghostBookshelf.Model.extend({
|
|||
return this.forge({id: options.id})
|
||||
.fetch(options)
|
||||
.then(function destroyLabelsAndMember(label) {
|
||||
if (!label) {
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return label.related('members')
|
||||
.detach(null, options)
|
||||
.then(function destroyLabels() {
|
||||
|
|
|
@ -117,6 +117,10 @@ Tag = ghostBookshelf.Model.extend({
|
|||
return this.forge({id: options.id})
|
||||
.fetch(options)
|
||||
.then(function destroyTagsAndPost(tag) {
|
||||
if (!tag) {
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return tag.related('posts')
|
||||
.detach(null, options)
|
||||
.then(function destroyTags() {
|
||||
|
|
Loading…
Add table
Reference in a new issue