fix: handle catex error

This commit is contained in:
Rotimi Best
2024-04-09 21:34:01 +01:00
parent 1058894127
commit 37f1466932
+8 -1
View File
@@ -6,9 +6,13 @@ const router = express.Router();
// localhost:3002/katex // localhost:3002/katex
router.get('/', async (req, res) => { router.get('/', async (req, res) => {
try {
const original = req._parsedUrl.search; const original = req._parsedUrl.search;
const latexString = original.replace('?', '').replaceAll('+', '+').replaceAll('&space;', ''); const latexString = original
.replace('?', '')
.replaceAll('+', '+')
.replaceAll('&space;', '');
console.log({ latexString }); console.log({ latexString });
const html = katex.renderToString(latexString, { const html = katex.renderToString(latexString, {
@@ -19,6 +23,9 @@ router.get('/', async (req, res) => {
console.log({ html }); console.log({ html });
res.send(html); res.send(html);
} catch (error) {
res.send('failed');
}
}); });
module.exports = router; module.exports = router;