petkaantonov / core-error-predicates Goto Github PK
View Code? Open in Web Editor NEWError predicate functions for operational errors thrown by node core.
License: MIT License
Error predicate functions for operational errors thrown by node core.
License: MIT License
Would make something like this possible:
var Err = require('core-error-predicates').Errors
// later
promise.catch(Err.EOF, e => ...)
Remains succinct without the need to .globalize()
(and doesn't break static analysis tools)
node 5.x+
{
"name": "RequestError",
"message": "Error: ESOCKETTIMEDOUT",
"cause": {
"code": "ESOCKETTIMEDOUT",
"connect": false
},
"error": {
"code": "ESOCKETTIMEDOUT",
"connect": false
},
"timeout": 60000,
}
}
This script below should result in an exception being caught by the FileNotFoundError
predicate. Right?
Instead I'm seeing
Unhandled rejection Error: ENOENT: no such file or directory, open 'blah.txt'
at Error (native)
#!/usr/bin/env node
var Promise = require('bluebird');
require('core-error-predicates').globalize();
var fs = Promise.promisifyAll(require('fs'));
fs.readFileAsync("blah.txt", "utf8").then(function(contents) {
console.log("file contents:", contents);
})
.catch(FileNotFoundError, function(e) {
console.log("file blah.txt does not exist");
})
.catch(FileAccessError, function(e) {
console.log("no permissions to access blah.txt");
});
node 0.10.32, simply requiring as in the example
/Users/duane/Development/remailer/node_modules/core-error-predicates/index.js:42
Object.setPrototypeOf(CustomError, Error);
^
TypeError: Object function Object() { [native code] } has no method 'setPrototypeOf'
at createClass (/Users/duane/Development/remailer/node_modules/core-error-predicates/index.js:42:12)
at addError (/Users/duane/Development/remailer/node_modules/core-error-predicates/index.js:8:16)
at Object.<anonymous> (/Users/duane/Development/remailer/node_modules/core-error-predicates/index.js:47:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/duane/Development/remailer/test.js:1:63)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.