How to use the @hapi/boom.isBoom function in @hapi/boom

To help you get started, we’ve selected a few @hapi/boom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onbjerg / micro-boom / lib / index.js View on Github external
// Determine status code in determined order
      let statusCode = res.statusCode || 500
      if (Boom.isBoom(err)) {
        statusCode = err.output.statusCode
      } else if (err.statusCode) {
        statusCode = err.statusCode
      }

      // Since it's an error, it's safe to assume <400
      // status codes are a mistake.
      if (statusCode < 400) {
        statusCode = 500
      }

      // Wrap the error and generate the response
      const error = Boom.isBoom(err) ? err : Boom.boomify(err, { statusCode })

      // Add WWW-Authenticate challenge to headers for 401 responses
      if (statusCode === 401 && error.data && error.data.challenge) {
        res.setHeader('WWW-Authenticate', error.data.challenge)
      }

      send(
        res,
        statusCode,
        Object.assign({},
          error.output.payload,
          error.data && { data: error.data }
        )
      )
    }
  }
github mark-bradshaw / mrhorse / lib / index.js View on Github external
const negotiateError = (err) => {

    if (_.isError(err)) {
        if (!Boom.isBoom(err)) {
            Boom.boomify(err, { statusCode: 403, override: false });
        }

        return err;
    }

    // In case someone throws a string or something equally terrifying
    return Boom.forbidden(err);
};
github hapijs / cookie / lib / index.js View on Github external
if (settings.keepAlive) {
                        h.state(settings.name, session);
                    }

                    return h.authenticated({ credentials, artifacts: session });
                }
                catch (err) {

                    Bounce.rethrow(err, 'system');

                    if (settings.cookie.clearInvalid) {
                        h.unstate(settings.name);
                    }

                    const unauthorized = Boom.isBoom(err) && err.typeof === Boom.unauthorized ? err : Boom.unauthorized('Invalid cookie');
                    return unauthenticated(unauthorized, { credentials, artifacts: session });
                }
            };
github RedHatWorkshops / dayinthelife-streaming / projects / module-0-ui-mobile-new / index.js View on Github external
app.use((err, req, res, next) => {
  log.error(err, `error processing a request ${req.method} ${req.originalUrl}`)

  if (boom.isBoom(err)) {
    res.status(err.output.statusCode).end(err.output.payload.message)
  } else {
    res.status(500).end('Internal Server Error')
  }
})
github tanem / express-bookshelf-realworld-example-app / lib / middleware / handle-boom-error.js View on Github external
module.exports = (err, req, res, next) => {
  if (Boom.isBoom(err)) {
    if (err.output.statusCode === 422) {
      return res.status(err.output.statusCode).json({
        errors: err.data,
      });
    }

    if (config.get('env') === 'production') {
      return res.status(err.output.statusCode).json({
        errors: {
          message: err.message,
          error: {},
        },
      });
    }

    req.log.error(err.stack);