Skip to content

Commit

Permalink
馃帹 Improved pagination misusage error
Browse files Browse the repository at this point in the history
refs TryGhost/Product#41, refs TryGhost/gscan#85

- if you are using the pagination helper not inside a resource context, you will receive an error
- improve error message, because it was not clear what happened
- downgrade error level to normal, because it's not a critical error from Ghost's perspective, from user perspective it is
- added help docs link and added a callout to our docs
  • Loading branch information
kirrg001 authored and kevinansfield committed Nov 28, 2017
1 parent 2f23cd3 commit e807526
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion core/server/helpers/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ var proxy = require('./proxy'),
pagination = function (options) {
if (!_.isObject(this.pagination) || _.isFunction(this.pagination)) {
throw new errors.IncorrectUsageError({
message: i18n.t('warnings.helpers.pagination.invalidData')
level: 'normal',
message: i18n.t('warnings.helpers.pagination.invalidData'),
help: 'https://themes.ghost.org/docs/pagination'
});
}

Expand Down
2 changes: 1 addition & 1 deletion core/server/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@
"isDeprecated": "Warning: pageUrl is deprecated, please use page_url instead\nThe helper pageUrl has been replaced with page_url in Ghost 0.4.2, and will be removed entirely in Ghost 0.6\nIn your theme's pagination.hbs file, pageUrl should be renamed to page_url"
},
"pagination": {
"invalidData": "pagination data is not an object or is a function",
"invalidData": "The \\{\\{pagination\\}\\} helper was used outside of a paginated context. See https://themes.ghost.org/docs/pagination.",
"valuesMustBeDefined": "All values must be defined for page, pages, limit and total",
"nextPrevValuesMustBeNumeric": "Invalid value, Next/Prev must be a number",
"valuesMustBeNumeric": "Invalid value, check page, pages, limit and total are numbers"
Expand Down
6 changes: 3 additions & 3 deletions core/test/unit/helpers/pagination_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('{{pagination}} helper', function () {
return function () {
helpers.pagination.call(data);
};
};
}, expectedMessage = 'The {{pagination}} helper was used outside of a paginated context. See https://themes.ghost.org/docs/pagination.';

runHelper('not an object').should.throwError('pagination data is not an object or is a function');
runHelper('not an object').should.throwError(expectedMessage);
runHelper(function () {
}).should.throwError('pagination data is not an object or is a function');
}).should.throwError(expectedMessage);
});

it('can render single page with no pagination necessary', function () {
Expand Down

0 comments on commit e807526

Please sign in to comment.