Commit a83ae523 authored by John Crepezzi's avatar John Crepezzi
Browse files

Catch exceptions

parent 83b8f3f5
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -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) {
  try {
    var _this = this;
    fs.mkdir(this.basePath, '700', function() {
    fs.writeFile(_this.basePath + '/' + hashlib.md5(key), data, 'utf8', function() {
      callback(true); // TODO handle errors
      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