From a83ae523b4c7c47c6f169eafc06d7521f0c9e0a8 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Fri, 18 Nov 2011 18:08:04 -0500 Subject: [PATCH] Catch exceptions --- lib/file_document_store.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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