🐛 fixed error message code for HB translate helper (#15529)

closes: https://github.com/TryGhost/Ghost/issues/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`.
This commit is contained in:
Christa 2022-10-12 13:14:53 -07:00 committed by GitHub
parent 8374c73e52
commit 87d21662bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {