🐛 Fixed pagination error (#9243)

no issue

- see explanation https://github.com/TryGhost/Ghost/pull/8129#issuecomment-286061529
- we catch the db error if it occurs, we can't simply check the length of the page param, because sqlite/mysql behaves differently
This commit is contained in:
Katharina Irrgang 2017-11-14 13:47:58 +01:00 committed by Kevin Ansfield
parent bcc98e5536
commit 76689ecbee
1 changed files with 10 additions and 0 deletions

View File

@ -2,6 +2,8 @@
//
// Extends Bookshelf.Model with a `fetchPage` method. Handles everything to do with paginated requests.
var _ = require('lodash'),
errors = require('../../errors'),
i18n = require('../../i18n'),
defaults,
paginationUtils,
pagination;
@ -189,6 +191,14 @@ pagination = function pagination(bookshelf) {
collection: fetchResult,
pagination: paginationUtils.formatResponse(countResult[0] ? countResult[0].aggregate : 0, options)
};
})
.catch(function (err) {
// e.g. offset/limit reached max allowed integer value
if (err.errno === 20 || err.errno === 1064) {
throw new errors.NotFoundError({message: i18n.t('errors.errors.pageNotFound')});
}
throw err;
});
});
}