Error handling for filesystem reads.

This commit is contained in:
Matjaz
2022-01-08 22:03:47 +01:00
parent 802f95f503
commit a7ad340283

View File

@ -8,6 +8,9 @@ function toTitleCase(str) {
/* GET home page. */
function articles(request, response) {
var articlesPage = `20 text/gemini\r\n\r\n# Articles by Uplink:SI\r\nList of Articles:\r\n${contents}\r\n`;
try {
var articleList = fs.readdirSync('./articles');
articleList.reverse();
var contents = '';
@ -16,21 +19,21 @@ function articles(request, response) {
title = toTitleCase(title);
contents += `=> /articles/${item} ${title}\r\n`;
});
response.send(`20 text/gemini\r\n
# Articles by Uplink:SI
List of Articles:
${contents}
`);
response.send(articlesPage);
} catch (error) {
response.error(51);
}
}
function articles_item(request, response) {
try {
var article = fs.readFileSync('./articles/' + request.params.item);
response.send(`20 text/gemini\r\n
${article}
=> /articles/ 📓Articles
=> / 🏡Home
`);
var articlePage = `20 text/gemini\r\n\r\n${article}\r\n\r\n=> /articles/ 📓Articles\r\n=> / 🏡Home\r\n`
response.send(articlePage);
} catch (error) {
response.error(51);
}
}
module.exports.articles = articles;