tgriesser / create-error Goto Github PK
View Code? Open in Web Editor NEWA simple utility for creating sub-classed errors in Javascript
License: MIT License
A simple utility for creating sub-classed errors in Javascript
License: MIT License
Looks like this module is rendering the bluebird module unusable (or the other way around) - care to comment here or there on how to fix it?
@tgriesser, maybe you can find my node-error useful ;)
I developed it to handle/log custom errors using Bookshelf and decided to share it
Specifically wanted to use the return of querystring
.parse() to save the response of an api call to a prop on my custom error. Took awhile to figure out that qs.parse() doesn't return a fully extended Object >.>
TypeError: target.hasOwnProperty is not a function
at clone (...\node_modules\create-error\create-error.js:94:16)
at attachProps (...\node_modules\create-error\create-error.js:82:26)
at new ErrorCtor (...\node_modules\create-error\create-error.js:28:5)
Can we maybe just change create-error.js#L94 to if (Object.prototype.hasOwnProperty(target, attr))
?
Hi there
Thanks for sharing your good work.
Just wondered what the meaning is of this variable cause
at:
https://github.com/tgriesser/create-error/blob/master/create-error.js#L34
To me it's the same as message and looks obsolete?
I just saw that I cannot set default messages like that:
var UnauthorizedError = createError(ClientError, 'UnauthorizedError', {
'status': 401,
'message': 'Unauthorized',
'details': {}
});
In the above example I expect that the following line
var err = new UnauthorizedError();
would automatically have the message 'Unauthorized' but currently it's undefined.
Any chance you could fix that?
Thx!
Would be great if we can pass on arguments to the constructor!
For example
var sub = new SubCustomError('My Message', {status: 404});
where 404 is a status whose default can be defined like that:
var SubCustomError = createError(MyCustomError, 'CoolSubError', {status: 400});
create-error has a pretty naive cloning implementation that seems to prevent you from storing any real objects on the error. For example:
var MyCustomError = createError('MyCustomError');
new MyCustomError('Bad!', {xhr: xhr});
Assuming that xhr
is an instance of XMLHttpRequest, you're actually going to get a new one on your error instance.
I guess this functionality was intended to allow you to add arbitrary simple but nested objects without fear of them being mutated, but it seems very limiting IMO.
Here's a testcase:
var createError = require('create-error');
var MyCustomError = createError('MyCustomError', {prop1: 1});
var SubCustomError = createError(MyCustomError, 'CoolSubError', {prop2: 2});
var sub = new SubCustomError('My Message', {prop3: 3});
console.log(sub.prop1); // undefined -> should be 1
console.log(sub.prop2); // 2
console.log(sub.prop3); // 3
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.