diff --git a/lib/file_document_store.js b/lib/file_document_store.js index b8aba00..5e0e1c9 100644 --- a/lib/file_document_store.js +++ b/lib/file_document_store.js @@ -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 FileDocumentStore.prototype.set = function(key, data, callback) { - var _this = this; - fs.mkdir(this.basePath, '700', function() { - fs.writeFile(_this.basePath + '/' + hashlib.md5(key), data, 'utf8', function() { - callback(true); // TODO handle errors + try { + var _this = this; + fs.mkdir(this.basePath, '700', function() { + fs.writeFile(_this.basePath + '/' + hashlib.md5(key), data, 'utf8', function(err) { + if (err) { + callback(false); + } + else { + callback(true); + } + }); }); - }); + } catch(err) { + callback(false); + } }; // Get data from a file from key