Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created December 24, 2014 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/e04378e414b46886e5f2 to your computer and use it in GitHub Desktop.
Save Raynos/e04378e414b46886e5f2 to your computer and use it in GitHub Desktop.
'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