Skip to content

Commit

Permalink
Merge pull request #2106 from /issues/2102
Browse files Browse the repository at this point in the history
Fail-safe to avoid crash on ejs rendering error
  • Loading branch information
parmentf authored Jul 19, 2024
2 parents 96145ea + fa801fa commit d9209d2
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/api/models/front.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTheme } from '@mui/material/styles';
import { assign } from 'lodash';
import { assign, escape } from 'lodash';
import { getTheme } from './themes';
import { version } from '../../../package.json';
import ejs from 'ejs';
Expand Down Expand Up @@ -64,10 +64,25 @@ export const createMuiTheme = (lodexTheme) => {
* @return {Promise<string>}
*/
const renderTemplate = (file, data) => {
return ejs.renderFile(file, data, {
async: true,
beautify: true,
root: path.dirname(file),
return new Promise((resolve) => {
ejs.renderFile(file, data, {
async: true,
beautify: true,
root: path.dirname(file),
})
.then(resolve)
.catch((reason) => {
resolve(`<!DOCTYPE html>
<html lang="en">
<head>
<title>Server Side Rendering Error</title>
</head>
<body>
<h1>Server Side Rendering Error</h1>
<p>${escape(reason)}</p>
</body>
</html>`);
});
});
};

Expand Down

0 comments on commit d9209d2

Please sign in to comment.