Skip to content
Browse files

catch invalid jsons

  • Loading branch information...
1 parent e06c6ea commit e3aa9d5c525c5f7e44153f81375e9464c5bee3b9 Markus Tiefenbacher committed Dec 21, 2013
Showing with 18 additions and 2 deletions.
  1. +18 −2 app.js
View
20 app.js
@@ -79,7 +79,13 @@ var async = require('async');
if (err) {
return callback('Item not found!');
} else {
- data = JSON.parse(data);
+
+ try {
+ data = JSON.parse(data);
+ } catch(e) {
+ return callback('File invalid!');
+ }
+
callback(false, data);
}
});
@@ -153,7 +159,17 @@ var async = require('async');
var q = async.queue(function(file, cb) {
fs.readFile(db+'/'+file, function(err, data) {
if(!err) {
- filesArray.push(JSON.parse(data));
+
+ try {
+ data = JSON.parse(data)
+ } catch(e) {
+ console.log('File invalid!', data);
+ }
+
+ if(typeof data !== 'string') {
+ filesArray.push(data);
+ }
+
}
cb();
});

0 comments on commit e3aa9d5

Please sign in to comment.
Something went wrong with that request. Please try again.