Code Monkey home page Code Monkey logo

Comments (3)

gonenduk avatar gonenduk commented on May 20, 2024

I use Celebrate (Joi) to validate the endpoints input and Boom (made by the same person who made Joi) to report errors. With boom, the error information is not the error output. It has a special output.payload sub object which you send back to the client, while the rest of the info is for your own use (like writing to log files). I make sure to throw only Boom errors in my code, however Joi and system errors are not.. so my API error handler look like:

(err, req, res, next) => {
    const errPayload = Boom.wrap(err, err.isJoi ? 400 : 500).output.payload;
    if (errPayload.statusCode == 500) {
      logger.error(err.stack);
    }
    res.status(errPayload.statusCode).json(errPayload);
  }

In the code, I convert all errors to Boom errors (only if they are not ones already) and add the right status. Then I return the error output payload.

from celebrate.

arb avatar arb commented on May 20, 2024

Yeah that's a fine way to do it. In your case, using your own error handler would probably be the way to go as I'm not planning on introducing boom into this module. This bug is for specifically Celebrate.errors() which leaks the entire validated object back to the client.

I'll probably just end up copying what hapi does when it formats joi errors.

from celebrate.

arb avatar arb commented on May 20, 2024

After reviewing this, I've removed the bug label. Worse case scenario is the client gets back the sent object which they've already got. So no big deal.

from celebrate.

Related Issues (20)

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.