How to use the celebrate.isCelebrate function in celebrate

To help you get started, we’ve selected a few celebrate 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 mozilla / fxa-content-server / server / lib / routes.js View on Github external
app.use((err, req, res, next) => {
      if (err && isCelebrate(err)) {
        logger.error('validation.failed', { err, method: req.method, path: req.url });
      }
      defaultErrorHandler(err, req, res, next);
      // capture validation errors
      raven.ravenModule.captureException(err);
    });
  };
github minhuyen / generator-expressjs-rest / generators / app / templates / backend / src / helpers / handle-errors.js View on Github external
export const errorHandle = (error, req, res, next) => {
  if (typeof error === 'string') {
    // custom application error
    return Response.error(res, { message: error });
  } else if (isCelebrate(error)) {
    logger.error('isCelebrate %s', isCelebrate(error));
    const { joi } = error;
    return Response.error(res, {
      message: 'Invalid request data. Please review request and try again.',
      code: joi.name,
      errors: joi.details.map(({ message, type }) => ({
        message: message.replace(/['"]/g, ''),
        type
      }))
    });
  } else if (error.name === 'CastError' && error.kind === 'ObjectId') {
    return Response.error(res, {
      // code: error.name,
      message: 'malformatted id'
    });
  } else if (error.name === 'ValidationError') {
github minhuyen / generator-expressjs-rest / generators / app / templates / backend / src / helpers / handle-errors.js View on Github external
export const errorHandle = (error, req, res, next) => {
  if (typeof error === 'string') {
    // custom application error
    return Response.error(res, { message: error });
  } else if (isCelebrate(error)) {
    logger.error('isCelebrate %s', isCelebrate(error));
    const { joi } = error;
    return Response.error(res, {
      message: 'Invalid request data. Please review request and try again.',
      code: joi.name,
      errors: joi.details.map(({ message, type }) => ({
        message: message.replace(/['"]/g, ''),
        type
      }))
    });
  } else if (error.name === 'CastError' && error.kind === 'ObjectId') {
    return Response.error(res, {
      // code: error.name,
      message: 'malformatted id'
    });
  } else if (error.name === 'ValidationError') {
    return Response.error(res, {