Created
November 29, 2016 12:42
-
-
Save stuf/35043c5b025bf551a58e7e6bc9ffe1c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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