Code Monkey home page Code Monkey logo

create-error's People

Contributors

tgriesser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

create-error's Issues

node-error

@tgriesser, maybe you can find my node-error useful ;)

I developed it to handle/log custom errors using Bookshelf and decided to share it

clone() throws on props set to objects not prototypically extended from Object

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)) ?

Allow default messages

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!

Allow arguments in constructor

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});

Why clone props?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.