Created
December 24, 2014 01:25
-
-
Save Raynos/e04378e414b46886e5f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
/*usage: | |
```js | |
var IOError = require('error/io'); | |
var fs = require('fs'); | |
fs.readFile(fPath, function (err, file) { | |
if (err) { | |
throw IOError(err, 'failed to read file'); | |
} | |
// do stuff with file | |
}); | |
``` | |
*/ | |
module.exports = IOError; | |
function IOError(originalError, prefix) { | |
var err = new Error(prefix + ': ' + originalError.message); | |
Object.defineProperty(err, 'type', { | |
value: 'error.IOError', | |
configurable: true, | |
enumerable: true | |
}); | |
err.name = 'WrappedIOError'; | |
err.statusCode = 500; | |
Object.defineProperty(err, 'original', { | |
value: originalError, | |
configurable: true, | |
enumerable: false | |
}); | |
return err; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment