Giter Site home page Giter Site logo

Comments (6)

dougwilson avatar dougwilson commented on April 25, 2024

We match the way throw works only:

$ node
> throw {message: 'server error', status: 401}
[object Object]

from errorhandler.

dougwilson avatar dougwilson commented on April 25, 2024

Actually, I was thinking this was a different module. Since this module's only purpose is for debugging, we can change it to use util.inspect to stringify non-Error objects. I would still highly discourage you from using those, mainly because you don't get a stack trace and so they are of marginal use.

from errorhandler.

alexbeletsky avatar alexbeletsky commented on April 25, 2024

I'm thinking both, correction of this module and correction of my code.. What I get used to use is returning simple object into callback, signaling there is an error. As far as I can see, many projects still using that, isn't it?

I would still highly discourage you from using those, mainly because you don't get a stack trace and so they are of marginal use.

It makes sense, probably Error is better. Anyways, it will be nice if both Error and non-Error object have clear output.

from errorhandler.

dougwilson avatar dougwilson commented on April 25, 2024

far as I can see, many projects still using that, isn't it?

That doesn't mean they should; the value you pass as err should always be an instanceof Error as it it should always be something would would have thrown.

from errorhandler.

alexbeletsky avatar alexbeletsky commented on April 25, 2024

Will take into consideration. So, for that particular case - if think it's enough to

        // write error to console
        if (env !== 'test') {
            console.error(err.stack || err)
        }

If you are fine with that, I can pack an PR.

Btw, it says development-only purpose? What's recommended to use in production.. or only custom one?

from errorhandler.

dougwilson avatar dougwilson commented on April 25, 2024

So, for that particular case - if think it's enough to

No, use util.inspect -- we want to only send a string to console.error, really. The other things should be changed too, the text/plain and the html responses should also be changed to use util.inspect.

Btw, it says development-only purpose? What's recommended to use in production.. or only custom one?

A custom one or use nothing and let the express built-in stuff handle it. Using this will leak internal information to customers, like error messages and stack traces. This means if someone puts a ' in an input field and sees the SQL syntax incorrect error message, they instantly know you have a SQL injection vulnerability.

from errorhandler.

Related Issues (13)

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.