Skip to content

Instantly share code, notes, and snippets.

@stuf
Created November 29, 2016 12:42
Show Gist options
  • Save stuf/35043c5b025bf551a58e7e6bc9ffe1c6 to your computer and use it in GitHub Desktop.
Save stuf/35043c5b025bf551a58e7e6bc9ffe1c6 to your computer and use it in GitHub Desktop.
var Storage = require('FuseJS/Storage');
function FileNotFoundError(message) {
this.name = this.constructor.name;
this.message = message || 'file could not be found';
this.stack = (new Error()).stack;
}
FileNotFoundError.prototype = Object.create(Error.prototype);
FileNotFoundError.prototype.constructor = FileNotFoundError;
var tokens = {
FILE_NOT_FOUND: 'File could not be found'
};
module.exports = {
read: function (filename) {
return new Promise(function (resolve, reject) {
var failureHandler = function (err) {
if (err === tokens.FILE_NOT_FOUND) {
reject(new FileNotFoundError());
}
};
Storage.read(filename)
.then(resolve)
.catch(failureHandler);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment