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

To help you get started, we’ve selected a few http-status 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 kartikayg / StatusPage / incidents-service / src / server / routes / index.js View on Github external
router.use((err, req, res, next) => {

    switch (err.name) {

      // data input error
      case 'ValidationError':
      case 'IdNotFoundError':
      case 'UpdateNotAllowedError':
      case 'InvalidDateError':
      case 'InvalidIncidentStatusError':
        res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: err.message });
        break;

      // db/unknown errors.
      default:
        next(err);
        break;
    }

  });
github kartikayg / StatusPage / components-service / src / server / routes / component-group.js View on Github external
.patch((req, res, next) => {

      const data = req.sanitizedBody.component_group;

      // not a valid component group object sent
      if (!data || typeof data !== 'object') {
        res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: 'No component group data sent in this request.' });
      }
      else {
        componentGroupRepo.update(req.componentGroupObj, data).then(group => {
          res.json(group);
        }).catch(next);
      }

    })
github kartikayg / StatusPage / notification-service / src / server / routes / subscription.js View on Github external
.post((req, res, next) => {

      const data = req.sanitizedBody.subscription;

      // not a valid subscription object sent
      if (!data || typeof data !== 'object') {
        res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: 'No subscription data sent in this request.' });
      }
      else {
        subscriptionRepo.ofType(data.type).then(repo => {
          return repo.subscribe(data);
        }).then(newSubscription => {
          res.json(newSubscription);
        }).catch(next);
      }
    });
github kartikayg / StatusPage / api-gateway / src / server / routes / v1 / index.js View on Github external
router.use((err, req, res, next) => {

    switch (err.name) {

      // data input error
      case 'InvalidCredentialsError':
        res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: err.message });
        break;

      // db/unknown errors.
      default:
        next(err);
        break;
    }

  });
github kartikayg / StatusPage / incidents-service / src / server / routes / incident.js View on Github external
.patch((req, res, next) => {

      const { incidentUpdateId } = req.sanitizedParams;
      const data = req.sanitizedBody.update;

      // not a valid incident object sent
      if (!data || typeof data !== 'object') {
        res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: 'No update data sent in this request.' });
      }
      else {

        // if message passed, keep the original. it could contain some html chars which will
        // be sanitized later.
        if (data.message) {
          data.message = req.body.update.message;
        }

        req.repo.changeIncidentUpdateEntry(req.incidentObj, incidentUpdateId, data)
          .then(updIncident => {
            res.json(updIncident);
          })
          .catch(next);

      }
github kartikayg / StatusPage / notification-service / src / server / routes / index.js View on Github external
router.use((err, req, res, next) => {

    switch (err.name) {

      // data input error
      case 'ValidationError':
      case 'IdNotFoundError':
      case 'InvalidSubscriptionTypeError':
      case 'DuplicatedSubscriptionError':
        res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: err.message });
        break;

      // db/unknown errors.
      default:
        next(err);
        break;
    }

  });
github kartikayg / StatusPage / components-service / src / server / routes / index.js View on Github external
router.use((err, req, res, next) => {

    switch (err.name) {

      // data input error
      case 'ValidationError':
      case 'IdNotFoundError':
        res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: err.message });
        break;

      // db/unknown errors.
      default:
        next(err);
        break;
    }

  });
github waldemarnt / testable-nodejs-api / controllers / books.js View on Github external
    .catch(error => errorResponse(error.message, HttpStatus.UNPROCESSABLE_ENTITY));
  }
github Codeminer42 / cm42-central / spec / javascripts / actions / notifications_spec.js View on Github external
describe('when response error is an unprocessable_entity', () => {
      const error = {
        response: {
          status: status.UNPROCESSABLE_ENTITY,
          data: {
            story: {
              errors: {}
            }
          }
        }
      };

      it('dispatches addValidationNotifications', () => {
        const FakeNotification = {
          createNotification,
          types
        };

        const fakeDispatch = sinon.stub();
github Codeminer42 / cm42-central / app / assets / javascripts / actions / notifications.js View on Github external
(dispatch, getState, { Notification }) => {
    const type = Notification.types.ERROR;

    switch (error.response.status) {
      case status.UNPROCESSABLE_ENTITY:
        return dispatch(
          addValidationNotifications(error.response.data.story.errors)
        );
      case status.UNAUTHORIZED:
        return dispatch(
          addNotification(
            Notification.createNotification({
              type,
              message: I18n.t('users.You are not authorized to perform this action')
            })
          )
        );
      case status.NOT_FOUND:
        return dispatch(
          addNotification(
            Notification.createNotification({