Skip to content

Commit

Permalink
🐛 fixed error message code for HB translate helper (#15529)
Browse files Browse the repository at this point in the history
closes: #15500

- Per the issue, Ghost has a policy to never throw 500 Internal Server errors for theme issues. This change adds a check inside of `ghost\core\core\frontend\helpers\t.js` if `text` or `options` is undefined, to throw an `IncorrectUsageError` error within the function.
- Messaging was borrowed from `ghost\core\core\frontend\web\middleware\error-handler.js`.
  • Loading branch information
cweave authored Oct 12, 2022
1 parent 8374c73 commit 87d2166
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ghost/core/core/frontend/helpers/t.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@
// {{tags prefix=(t " on ")}}

const {themeI18n} = require('../services/handlebars');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');

const messages = {
oopsErrorTemplateHasError: 'Oops, seems there is an error in the template.'
};

module.exports = function t(text, options) {
if (text === undefined && options === undefined) {
throw new errors.IncorrectUsageError({
message: tpl(messages.oopsErrorTemplateHasError)
});
}

const bindings = {};
let prop;
for (prop in options.hash) {
Expand Down

0 comments on commit 87d2166

Please sign in to comment.