How to use the express-validation.ValidationError function in express-validation

To help you get started, we’ve selected a few express-validation 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 frontendbr / eventos-api / test / middleware / init.error.handler.middleware.spec.js View on Github external
const expressValidation = require('express-validation')
      const app = {
        use: function (next) {
          middleware = next
        }
      }

      error({
        app
      })

      const errors = {}
      const options = {
        status: 400
      }
      const errorThrow = new expressValidation.ValidationError(errors, options)
      const req = {}
      const res = {
        status: () => {}
      }

      const status = sinon.stub(res, 'status').returns({
        json: () => {}
      })

      // simulando a chamada do middleware
      middleware(errorThrow, req, res, next)
      status.should.have.been.calledWith(400)
    })
github andy6804tw / RESTful_API_start_kit / src / config / express.js View on Github external
app.use((err, req, res, next) => {console.log('1')
  let errorMessage;
  let errorCode;
  let errorStatus;
  // express validation error 所有傳入參數驗證錯誤
  if (err instanceof expressValidation.ValidationError) {
    if (err.errors[0].location === 'query' || err.errors[0].location === 'body') {
      errorMessage = err.errors[0].messages;
      errorCode = 400;
      errorStatus = httpStatus.BAD_REQUEST;
    }
    const error = new APPError.APIError(errorMessage, errorStatus, true, errorCode);
    return next(error);
  }
  return next(err);
});
github kunalkapadia / express-mongoose-es6-rest-api / config / express.js View on Github external
app.use((err, req, res, next) => {
  if (err instanceof expressValidation.ValidationError) {
    // validation error contains errors which is an array of error each containing message[]
    const unifiedErrorMessage = err.errors.map(error => error.messages.join('. ')).join(' and ');
    const error = new APIError(unifiedErrorMessage, err.status, true);
    return next(error);
  } else if (!(err instanceof APIError)) {
    const apiError = new APIError(err.message, err.status, err.isPublic);
    return next(apiError);
  }
  return next(err);
});
github garage-it / SmartHouse-backend / src / config / express.js View on Github external
app.use((err, req, res, next) => {
    if (err instanceof expressValidation.ValidationError) {
        // validation error contains errors which is an array of error each containing message[]
        const unifiedErrorMessage = err.errors.map(error => error.messages.join('. ')).join(' and ');
        const error = new APIError(unifiedErrorMessage, err.status, true);
        return next(error);
    } else if (!(err instanceof ExtendableError)) {
        const apiError = new APIError(err.message, err.status, err.isPublic);
        return next(apiError);
    }
    return next(err);
});
github amida-tech / api-boilerplate / config / express.js View on Github external
app.use((err, req, res, next) => {
    if (err instanceof expressValidation.ValidationError) {
        // validation error contains errors which is an array of error each containing message[]
        const unifiedErrorMessage = err.errors.map((error) => error.messages.join('. ')).join(' and ');
        const error = new APIError(unifiedErrorMessage, err.status, true);
        return next(error);
    } if (!(err instanceof APIError)) {
        const apiError = new APIError(err.message, err.status, err.isPublic);
        return next(apiError);
    }
    return next(err);
});
github amaurymartiny / timed / app / server / config / express.js View on Github external
app.use((err, req, res, next) => {
  if (err instanceof expressValidation.ValidationError) {
    // validation error contains errors which is an array of error each containing message[]
    const unifiedErrorMessage = err.errors.map(error => error.messages.join('. ')).join(' and ');
    const error = new APIError(unifiedErrorMessage, err.status, true);
    return next(error);
  } else if (!(err instanceof APIError)) {
    const apiError = new APIError(err.message, err.status, err.isPublic);
    return next(apiError);
  }
  return next(err);
});
github eclipse / repairnator / website / repairnator-mongo-rest-api / config / express.js View on Github external
app.use((err, req, res, next) => {
  if (err instanceof expressValidation.ValidationError) {
    // validation error contains errors which is an array of error each containing message[]
    const unifiedErrorMessage = err.errors.map(error => error.messages.join('. ')).join(' and ');
    const error = new APIError(unifiedErrorMessage, err.status, true);
    return next(error);
  } else if (!(err instanceof APIError)) {
    const apiError = new APIError(err.message, err.status, err.isPublic);
    return next(apiError);
  }
  return next(err);
});
github SoftwareEngineeringDaily / software-engineering-daily-api / config / express.js View on Github external
app.use((err, req, res, next) => {
  if (err instanceof expressValidation.ValidationError) {
    // validation error contains errors which is an array of error each containing message[]
    const unifiedErrorMessage = err.errors.map(error => error.messages.join('. ')).join(' and ');
    const error = new APIError(unifiedErrorMessage, err.status, true);
    return next(error);
  } else if (!(err instanceof APIError)) {
    const apiError = new APIError(err.message, err.status, err.isPublic);
    return next(apiError);
  }
  return next(err);
});
github mpayetta / node-es6-rest-api / config / express.js View on Github external
app.use((err, req, res, next) => {
  if (err instanceof expressValidation.ValidationError) {
    res.status(err.status).json(err);
  } else {
    res.status(500)
      .json({
        status: err.status,
        message: err.message
      });
  }
});
github Madmous / madClones / server / trello-microservice / src / app.js View on Github external
app.use((err, req, res, next) => {
  if (err instanceof expressValidation.ValidationError) {
    const unifiedErrorMessage = err.errors
      .map(error => error.messages.join(". "))
      .join(" and ");

    return res.status(err.status).json({
      message: unifiedErrorMessage
    });
  }
});

express-validation

express-validation is a middleware that validates a request and returns a response with errors; if any of the configured validation rules fail.

MIT
Latest version published 5 months ago

Package Health Score

76 / 100
Full package analysis