Skip to content

Commit

Permalink
catch invalid jsons
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Tiefenbacher committed Dec 21, 2013
1 parent e06c6ea commit e3aa9d5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app.js
Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit e3aa9d5

Please sign in to comment.