How to use the http-status-codes.UNPROCESSABLE_ENTITY function in http-status-codes

To help you get started, we’ve selected a few http-status-codes 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 RequestNetwork / requestNetwork / packages / request-node / src / request / getTransactionsByTopic.ts View on Github external
clientRequest: any,
  serverResponse: any,
  dataAccess: DataAccess,
): Promise {
  // Retrieves data access layer
  let transactions;

  // As the Node doesn't implement a cache, all transactions have to be retrieved directly on IPFS
  // This operation can take a long time and then the timeout of the request should be increase
  // PROT-187: Decrease or remove this value
  clientRequest.setTimeout(REQUEST_TIMEOUT);

  // Verifies if data sent from get request are correct
  // clientRequest.query is expected to contain the topic of the transactions to search for
  if (!clientRequest.query || !clientRequest.query.topic) {
    serverResponse.status(httpStatus.UNPROCESSABLE_ENTITY).send('Incorrect data');
  } else {
    try {
      // parse updatedBetween because in query everything is string
      let timestampBoundaries: { from: number; to: number } | undefined;
      if (clientRequest.query.timestampBoundaries) {
        timestampBoundaries = JSON.parse(clientRequest.query.timestampBoundaries);
      }

      transactions = await dataAccess.getTransactionsByTopic(
        clientRequest.query.topic,
        timestampBoundaries,
      );

      serverResponse.status(httpStatus.OK).send(transactions);
    } catch (e) {
      // tslint:disable-next-line:no-console
github RequestNetwork / requestNetwork / packages / request-node / src / request / persistTransaction.ts View on Github external
// Retrieves data access layer
  let dataAccessResponse;

  // Used to compute request time
  const requestStartTime = Date.now();

  // Set the timeout from the value from config and convert seconds to milliseconds
  // tslint:disable:no-magic-numbers
  clientRequest.setTimeout(getPersistTransactionTimeout() * 1000);

  // Verifies if data send from post are correct
  // clientRequest.body is expected to contain data for data-acces layer:
  // transactionData: data of the transaction
  // topics (optional): arbitrary strings that reference the transaction
  if (!clientRequest.body || !clientRequest.body.transactionData || !clientRequest.body.channelId) {
    serverResponse.status(httpStatus.UNPROCESSABLE_ENTITY).send('Incorrect data');
  } else {
    try {
      dataAccessResponse = await dataAccess.persistTransaction(
        clientRequest.body.transactionData,
        clientRequest.body.channelId,
        clientRequest.body.topics,
      );

      // Log the request time
      const requestEndTime = Date.now();
      logger.debug(`persistTransaction latency: ${requestEndTime - requestStartTime}ms`, ['metric', 'latency']);
      logger.debug(`persistTransaction successfully completed`, ['metric', 'successRate']);

      serverResponse.status(httpStatus.OK).send(dataAccessResponse);
    } catch (e) {
      logger.error(`persistTransaction error: ${e}`);
github uhlryk / my-express-react-seed / tests / server / user.js View on Github external
.end(function(err, res){
        expect(res.status).to.be.equal(httpStatus.UNPROCESSABLE_ENTITY);
        done();
      });
  });
github uhlryk / my-express-react-seed / tests / server / crud.js View on Github external
.end(function(err, res){
        expect(res.status).to.be.equal(httpStatus.UNPROCESSABLE_ENTITY);
        done();
      });
  });
github uhlryk / my-express-react-seed / src / server / apiRoutes / authentications.js View on Github external
router.post('/authentications/', function(req, res, next){
  var logger = req.app.get('logger');
  var actions = req.app.get('actions');
  var models = req.app.get('models');

  req.checkGroup('password');
  req.checkGroup('email');
  var errors = req.validationErrors();
  if (errors) {
    return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
  }
  var email = req.body.email;
  var password = req.body.password;

  actions.users.list({
    where: {
      email: email,
      status: models.user.STATUS.ACTIVE
    }
  }, (err, users) => {
    if(err) {
      logger.error('server error users', err);
      return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
    }
    if(!users || users.length === 0) {
      return res.status(httpStatus.NOT_FOUND).end();
github Prior99 / hyrest / packages / hyrest / src / answers.ts View on Github external
export function unprocessableEntity(arg1: T | string | Wrapper, arg2?: string): T {
    return answer(HTTP.UNPROCESSABLE_ENTITY, arg1, arg2);
}
github uhlryk / my-express-react-seed / src / server / routes / items.js View on Github external
}, (err, item) => {
    if(err instanceof ValidationError) {
      return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
    } else if(err) {
      logger.error('DB error item', err);
      return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
    }
    res.status(httpStatus.OK).json(item);
  });
});
github uhlryk / my-express-react-seed / src / server / apiRoutes / items / updateItem.js View on Github external
router.put('/items/:id', (req, res) => {
  var logger = req.app.get('logger');
  var actions = req.app.get('actions');
  req.checkGroup('name');
  var errors = req.validationErrors();
  if (errors) {
    return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
  }
  var name = req.body.name;
  actions.items.list({
    id: req.params.id
  }, (err, items) => {
    if (err) {
      logger.error('DB error item', err);
      return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
    }
    if (!items || items.length === 0) {
      return res.status(httpStatus.NOT_FOUND).end();
    }
    actions.items.update(items[0], {
      name
    }, (err, item) => {
      if (err) {
github uhlryk / my-express-react-seed / src / server / apiRoutes / users / resetPassword.js View on Github external
router.post('/users/resetPassword', (req, res) => {
  var logger = req.app.get('logger');
  var config = req.app.get('config');
  var actions = req.app.get('actions');
  var models = req.app.get('models');

  req.checkGroup('email');
  var errors = req.validationErrors();
  if (errors) {
    return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
  }
  var email = req.body.email;

  actions.users.list({
    where: {
      email: email,
      status: models.user.STATUS.ACTIVE
    }
  }, (err, users) => {
    if(err) {
      logger.error('DB error find reset user password configrmation', err);
      return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
    }
    if(!users || users.length === 0) {
      return res.status(httpStatus.NOT_FOUND).end();
    }
github uhlryk / my-express-react-seed / src / server / apiRoutes / users / resetPasswordConfirmation.js View on Github external
router.post('/users/resetPassword/confirmation', (req, res) => {
  var logger = req.app.get('logger');
  var config = req.app.get('config');
  var actions = req.app.get('actions');
  var models = req.app.get('models');

  req.checkGroup('password');
  var errors = req.validationErrors();
  if (errors) {
    return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
  }
  var password = req.body.password;

  actions.users.verifyResetPasswordToken(req.body.token, (err, response) => {
    if(err) {
      logger.error('server error reset user password configrmation', err);
      return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
    }
    actions.users.list({
      id: response.id
    }, (err, users) => {
      if(err) {
        logger.error('DB error find reset user password configrmation', err);
        return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
      }
      if(!users || users.length === 0 || users[0].status !== models.user.STATUS.ACTIVE) {