0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

🐛 Fixed 500 errors for invalid theme layouts (#19848)

ref ENG-742
ref https://linear.app/tryghost/issue/ENG-742

We don't do any parsing of layouts in gscan, which means themes can be
uploaded which use non-existent files for their layout.

We can catch the error in the res.render call, and wrap it, just like we
do for missing templates (e.g. the StaticRoutesRouter)
This commit is contained in:
Fabien 'egg' O'Carroll 2024-03-14 23:12:26 +07:00 committed by GitHub
parent f16d9802d0
commit aaa19a535a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,12 @@
const path = require('path');
const debug = require('@tryghost/debug')('services:routing:renderer:renderer');
const {IncorrectUsageError} = require('@tryghost/errors');
const setContext = require('./context');
const templates = require('./templates');
const tpl = require('@tryghost/tpl');
const messages = {
couldNotReadFile: 'Could not read file {file}'
};
/**
* @description Helper function to finally render the data.
@ -26,5 +32,17 @@ module.exports = function renderer(req, res, data) {
}
// Render Call
res.render(res._template, data);
res.render(res._template, data, function (err, html) {
if (err) {
if (err.code === 'ENOENT') {
return req.next(
new IncorrectUsageError({
message: tpl(messages.couldNotReadFile, {file: path.basename(err.path)})
})
);
}
req.next(err);
}
res.send(html);
});
};