diff --git a/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js b/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js index 7a1b9a3904..f62ad52d21 100644 --- a/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js +++ b/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js @@ -1,4 +1,6 @@ +const logger = require('@tryghost/logging'); const Collection = require('@tryghost/collections').Collection; +const sentry = require('../../../shared/sentry'); /** * @typedef {import('@tryghost/collections/src/CollectionRepository')} CollectionRepository */ @@ -61,28 +63,35 @@ module.exports = class BookshelfCollectionsRepository { withRelated: ['collectionPosts'] }); - return await Promise.all(models.map(model => this.#modelToCollection(model))); + return (await Promise.all(models.map(model => this.#modelToCollection(model)))).filter(entity => !!entity); } - #modelToCollection(model) { + async #modelToCollection(model) { const json = model.toJSON(); let filter = json.filter; if (json.type === 'automatic' && typeof filter !== 'string') { filter = ''; } - return Collection.create({ - id: json.id, - slug: json.slug, - title: json.title, - description: json.description, - filter: filter, - type: json.type, - featureImage: json.feature_image, - posts: json.collectionPosts.map(collectionPost => collectionPost.post_id), - createdAt: json.created_at, - updatedAt: json.updated_at - }); + + try { + return await Collection.create({ + id: json.id, + slug: json.slug, + title: json.title, + description: json.description, + filter: filter, + type: json.type, + featureImage: json.feature_image, + posts: json.collectionPosts.map(collectionPost => collectionPost.post_id), + createdAt: json.created_at, + updatedAt: json.updated_at + }); + } catch (err) { + logger.error(err); + sentry.captureException(err); + return null; + } } /**