Comments (9)
Related to #16.
Use new errors.NotFoundError instanceof Error
or errors.NotFoundError() instanceof Error
from node-common-errors.
However in http://bluebirdjs.com/docs/api/catch.html#filtered-catch:
somePromise.then(function() {
return a.b.c.d();
}).catch(TypeError, function(e) {
//If it is a TypeError, will end up here because
//it is a type error to reference property of undefined
}).catch(ReferenceError, function(e) {
//Will end up here if a was never declared at all
}).catch(function(e) {
//Generic catch-the rest, error wasn't TypeError nor
//ReferenceError
});
But I can't get this to work with common-errors
...
For a parameter to be considered a type of error that you want to filter, you need the constructor to have its .prototype property be instanceof Error.
Would be great if it worked with Bluebird catch out-of-the-box.
from node-common-errors.
I'm a bit surprised, because the author of bluebird himself helped me with a feature that should allow this to work. https://github.com/shutterstock/node-common-errors/blob/master/lib/internal/globalize.js
I'll for sure look into this.
from node-common-errors.
I added some tests to reproduce your issue and I could not.
var errors = require('common-errors');
var Promise = require('bluebird');
var caught_error_in_promise = false;
var promise = new Promise(function(res, rej) { res(true); }).then(function(){
throw new errors.TypeError("test error");
}).catch(TypeError, function(e){
caught_error_in_promise = true;
}).finally(function(){
console.log("CAUGHT ERROR?", caught_error_in_promise);
});
If you run this, what do you see?
from node-common-errors.
For that example I see CAUGHT ERROR? true
.
I am using babel with async/await. I'll see if I can write a script to reproduce it.
from node-common-errors.
@dfenster @vjpr were you ever able to get this working? I also cannot seem to do a filtered catch when using bluebird and common errors
from node-common-errors.
Ca you give me some sample code since I cannot reproduce the issue based on the explanation? I'll gladly look deeper then.
from node-common-errors.
It happens with NodeJS 8.x but not with NodeJS 6.x
from node-common-errors.
Can you provide more info? This is what I get:
➜ node-common-errors git:(master) ✗ npm test
[email protected] test /mnt/c/Users/DFenestrator/code/node-common-errors
mocha --recursive tests
AlreadyInUseError
✓ should work
ArgumentNullError
✓ should work
✓ should work without new
ArgumentError
✓ should work
✓ should work without new
AuthenticationRequiredError
✓ should work
✓ should work without new
ConnectionError
✓ should work
✓ should work without new
DataError
✓ should work
✓ should work without new
MemcachedError
✓ should work
✓ should work without new
MongoDBError
✓ should work
✓ should work without new
RedisError
✓ should work
✓ should work without new
RollbackError
✓ should work
✓ should work without new
SQLError
✓ should work
✓ should work without new
TransactionError
✓ should work
✓ should work without new
Error
✓ should work
✓ should work without new
classGenerator
✓ should work
✓ should be safe to use a name - strings only
✓ should be safe to use a name - word characters only
✓ should be safe to use custom arguments - array only
✓ should be safe to use custom arguments - array of strings only
✓ should be safe to use custom arguments - array of strings only
✓ should globalize errors
prependCurrentStack
✓ should work
global namespace
✓ should maintain a global namespace for instanceof
HttpStatusError
✓ should work with status code and message
✓ should work with status code
✓ should work with status code and message without new
✓ should work with status code without new
InvalidOperationError
✓ should work
✓ should work without new
DirectoryNotFoundError
✓ should work
✓ should work without new
DriveNotFoundError
✓ should work
✓ should work without new
EndOfStreamError
✓ should work
✓ should work without new
FileLoadError
✓ should work
✓ should work without new
FileNotFoundError
✓ should work
✓ should work without new
IOError
✓ should work
✓ should work without new
SocketError
✓ should work
✓ should work without new
errors.log
✓ should log a message
✓ log string error
✓ log error, no message
✓ log generic error
errorHandler
✓ should handle NotPermittedError
✓ should handle AuthenticationRequired
✓ should handle Validation
✓ should handle AlreadyInUse
✓ should handle ArgumentNull
✓ should handle ArgumentNull route param
✓ should handle ArgumentNull route param in express3
✓ should handle ArgumentNull POST
✓ should handle NotFoundError
✓ should handle Error
✓ should handle Error status
✓ should handle Error status
✓ should handle Error status
✓ should handle HttpStatusError (deprecated)
✓ should handle HttpStatusError
✓ should handle HttpStatusError 400
✓ should work with express 3
NotFoundError
✓ should work
✓ should work without new
NotImplementedError
✓ should work
✓ should work without new
NotPermittedError
✓ should work
✓ should work without new
NotSupportedError
✓ should work
✓ should work without new
OutOfMemoryError
✓ should work
✓ should work without new
RangeError
✓ should work
✓ should work without new
ReferenceError
✓ should work
✓ should work without new
StackOverflowError
✓ should work
✓ should work without new
SyntaxError
✓ should work
✓ should work without new
TimeoutError
✓ should work for durations
✓ should work
TypeError
✓ should work
✓ should work without new
URIError
✓ should work
✓ should work without new
ValidationError
✓ should work
nested errors
✓ should addError
✓ should addErrors
✓ should require an Array for addErrors
103 passing (309ms)
➜ node-common-errors git:(master) ✗ node -v
v8.12.0
from node-common-errors.
Related Issues (15)
- ValidationError is exported as errors.Validation HOT 1
- [Feature] Internval vs External
- [Q] Since SyntaxError is also built-in, how do you usually handle that? HOT 4
- Is it possible to customize the error messages? HOT 3
- Make `new` optional? HOT 2
- Append extra data to errors HOT 1
- Upgrade lodash HOT 1
- Reduce module load time HOT 4
- Unnecessary dependency bluebird. HOT 3
- Shutterstock user credentials must be included on the client? HOT 2
- Provide type definitions for common-errors HOT 8
- npm install fails HOT 1
- classGeneratorFn fail in web extensions HOT 2
- Cannot find module 'lodash' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-common-errors.