Catch exceptions

This commit is contained in:
John Crepezzi 2011-11-18 18:08:04 -05:00
parent 83b8f3f52d
commit a83ae523b4

View file

@ -11,12 +11,21 @@ var FileDocumentStore = function(options) {
// Save data in a file, key as md5 - since we don't know what we could be passed here // Save data in a file, key as md5 - since we don't know what we could be passed here
FileDocumentStore.prototype.set = function(key, data, callback) { FileDocumentStore.prototype.set = function(key, data, callback) {
try {
var _this = this; var _this = this;
fs.mkdir(this.basePath, '700', function() { fs.mkdir(this.basePath, '700', function() {
fs.writeFile(_this.basePath + '/' + hashlib.md5(key), data, 'utf8', function() { fs.writeFile(_this.basePath + '/' + hashlib.md5(key), data, 'utf8', function(err) {
callback(true); // TODO handle errors if (err) {
callback(false);
}
else {
callback(true);
}
}); });
}); });
} catch(err) {
callback(false);
}
}; };
// Get data from a file from key // Get data from a file from key