Skip to content

Commit 2ddef37

Browse files
committed
Added error handling
1 parent 55e01a9 commit 2ddef37

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ app.use(bodyParser.urlencoded({extended: true}));
2626

2727
app.get('/api/comments', function(req, res) {
2828
fs.readFile(COMMENTS_FILE, function(err, data) {
29+
if (err) console.log(err);
2930
res.setHeader('Cache-Control', 'no-cache');
3031
res.json(JSON.parse(data));
3132
});
3233
});
3334

3435
app.post('/api/comments', function(req, res) {
3536
fs.readFile(COMMENTS_FILE, function(err, data) {
37+
if (err) console.log(err);
3638
var comments = JSON.parse(data);
3739
comments.push(req.body);
3840
fs.writeFile(COMMENTS_FILE, JSON.stringify(comments, null, 4), function(err) {
41+
if (err) console.log(err);
3942
res.setHeader('Cache-Control', 'no-cache');
4043
res.json(comments);
4144
});

0 commit comments

Comments
 (0)