8680099765
refs #8222 - differentiate between errors and fatal errors - use gscan errors in theme middleware - Adds a new `error()` method to `currentActiveTheme` constructor which will return the errors we receive from gscan - In middleware, if a theme couldn't be activated because it's invalid, we'll fetch the erros and send them to our error handler. We also use a new property `hideStack` to control, if the stack (in dev mode and if available) should be shown or the gscan errors (in prod mode, or in dev if no stack error) - In our error handler we use this conditional to send a new property `gscan` to our error theme - In `error.hbs` we'll iterate through possible `gscan` error objects and render them. - remove stack printing - stack for theme developers in development mode doesn't make sense - stack in production doesn't make sense - the stack is usually hard to read - if you are developer you can read the error stack on the server log - utils.packages: transform native error into Ghost error - use `onlyFatalErrors` for gscan format and differeniate fatal errors vo.2 - optimise bootstrap error handling - transform theme is missing into an error - add new translation key - show html tags for error.hbs template: rule
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
var Promise = require('bluebird'),
|
|
config = require('../config'),
|
|
errors = require('../errors'),
|
|
i18n = require('../i18n'),
|
|
checkTheme;
|
|
|
|
checkTheme = function checkTheme(theme, isZip) {
|
|
var checkPromise,
|
|
// gscan can slow down boot time if we require on boot, for now nest the require.
|
|
gscan = require('gscan');
|
|
|
|
if (isZip) {
|
|
checkPromise = gscan.checkZip(theme, {
|
|
keepExtractedDir: true
|
|
});
|
|
} else {
|
|
checkPromise = gscan.check(theme.path);
|
|
}
|
|
|
|
return checkPromise.then(function resultHandler(checkedTheme) {
|
|
checkedTheme = gscan.format(checkedTheme, {
|
|
onlyFatalErrors: config.get('env') === 'production'
|
|
});
|
|
|
|
// CASE: production and no fatal errors
|
|
// CASE: development returns fatal and none fatal errors, theme is only invalid if fatal errors
|
|
if (!checkedTheme.results.error.length ||
|
|
config.get('env') === 'development' && !checkedTheme.results.hasFatalErrors) {
|
|
return checkedTheme;
|
|
}
|
|
|
|
return Promise.reject(new errors.ThemeValidationError({
|
|
message: i18n.t('errors.api.themes.invalidTheme'),
|
|
errorDetails: checkedTheme.results.error,
|
|
context: checkedTheme
|
|
}));
|
|
});
|
|
};
|
|
|
|
module.exports.check = checkTheme;
|