How to use the restify.InvalidArgumentError function in restify

To help you get started, we’ve selected a few restify 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 pcimino / nodejs-restify-mongodb / config / routes-user.js View on Github external
function deleteUser(req, res, next) {
     if (req.session && req.session.user) {
       if (req.session.user == req.params.id) {
         return next(new restify.InvalidArgumentError('User cannot delete themselves.'));
       }
        User.findById(req.params.id).remove(function (err) {
          if (!err) {
            // clean up archived status
            var query = SystemMessageArchive.where( 'userId', req.params.id );
            query.exec(function (err, sysMessageArr) {
            });
            var query2 = TermsAndConditionsArchive.where( 'userId', req.params.id );
            query2.exec(function (err, sysMessageArr) {
            });

            res.send({});
            return next();
          } else {
            return next(new restify.MissingParameterError('ObjectId required.'));
          }
github tes / seguir / server / index.js View on Github external
server.post(u('addFollower'), api.auth.checkRequest, function (req, res, next) {
    if (!req.params.user) {
      return next(new restify.InvalidArgumentError('You must provide a user.'));
    }
    if (!req.params.user_follower) {
      return next(new restify.InvalidArgumentError('You must provide a user_follower.'));
    }

    var visibility = req.params.visibility || null,
      backfill = req.params.backfill;

    coerce(req.keyspace, [req.params.user, req.params.user_follower], function (err, users) {
      if (err) { return next(_error(err)); }
      var user = users[0], user_follower = users[1];

      if (user_follower.toString() !== req.liu.user.toString()) {
        return next(new restify.ForbiddenError('You can only add your own follow relationships.'));
      }

      api.follow.addFollower(req.keyspace, user, user_follower, api.client.getTimestamp(), visibility, backfill, _response(res, next));
    });
github xpush / node-xpush / lib / util / utils.js View on Github external
exports.validEmptyParams = function (req, paramArray) {

  for (var i in paramArray) {
    if (!req.params[paramArray[i]]) {
      return new restify.InvalidArgumentError('[' + paramArray[i] + '] must be supplied');
    }
  }

  return false;
};
github Jigsaw-Code / outline-server / src / shadowbox / server / manager_service.ts View on Github external
public async setPortForNewAccessKeys(req: RequestType, res: ResponseType, next: restify.Next):
      Promise {
    try {
      logging.debug(`setPortForNewAccessKeys request ${JSON.stringify(req.params)}`);
      const port = req.params.port;
      if (!port) {
        return next(
            new restify.MissingParameterError({statusCode: 400}, 'Parameter `port` is missing'));
      } else if (typeof port !== 'number') {
        return next(new restify.InvalidArgumentError(
            {statusCode: 400},
            `Expected a numeric port, instead got ${port} of type ${typeof port}`));
      }
      await this.accessKeys.setPortForNewAccessKeys(port);
      this.serverConfig.data().portForNewAccessKeys = port;
      this.serverConfig.write();
      res.send(HttpSuccess.NO_CONTENT);
      next();
    } catch (error) {
      logging.error(error);
      if (error instanceof errors.InvalidPortNumber) {
        return next(new restify.InvalidArgumentError({statusCode: 400}, error.message));
      } else if (error instanceof errors.PortUnavailable) {
        return next(new restify.ConflictError(error.message));
      }
      return next(new restify.InternalServerError(error));
github tes / seguir / server / index.js View on Github external
server.post(u('acceptFriendRequest'), api.auth.checkRequest, function (req, res, next) {
    if (!req.params.friend_request) {
      return next(new restify.InvalidArgumentError('You must provide a friend_request guid.'));
    }
    api.friend.acceptFriendRequest(req.keyspace, req.liu.user, req.params.friend_request, _response(res, next));
  });
github phodal / freerice / server / service / authenticate.js View on Github external
Authenticate.prototype.login = function (req, res, next) {
    'use strict';
    var account = req.params;

    if (account.name === undefined || account.password === undefined) {
        return next(new restify.InvalidArgumentError('Name must be supplied'));
    }

    db.getPasswordByName(account.name, function (result) {
        bcrypt.compare(account.password, _.first(result).password, function(err, success) {
            if (success) {
                res.send({status: "success"});
            } else {
                res.send({status: "fail"});
            }
            next();
        });
    });
};
github e2ebridge / bpmn / lib / rest.js View on Github external
getNameWithCase(manager, processNameWithoutCase, function(err, processName){
        if(err){
            return sendError(err, next);
        }

        if(!processName){
            return next(new restify.InvalidArgumentError("Could not find process name '" + processNameWithoutCase + "'."));
        }

        manager.createProcess({id: processId, name: processName}, function(err, bpmnProcess){
            if(err){
                return sendError(err, next);
            }

            logger.setProcess(bpmnProcess);

            if (startProcess === undefined || startProcess) {
                startEventName = querystring.unescape(req.params.startEventName);

                try{
                    triggerEvent(bpmnProcess, logger, startEventName, req.body, true);
                } catch (e) {
                    return sendError(e, next);
github joyent / sdc-adminui / lib / adminui.js View on Github external
return servers.setup(req, res, next);
        }

        if (req.params.action === 'update-nics') {
            return servers.updateNics(req, res, next);
        }

        if (req.params.action === 'factory-reset') {
            return servers.factoryReset(req, res, next);
        }

        if (req.params.action === 'reboot') {
            return servers.reboot(req, res, next);
        }

        res.send(new restify.InvalidArgumentError('Unsupported action'));
        return next();
    });
github sensebox / openSenseMap-API / lib / requestUtils.js View on Github external
const validateTimeParameters = function (req, noTimeLimit) {
  const now = moment().utc(),
    toDate = req._userParams['to-date'],
    fromDate = req._userParams['from-date'];
  if (toDate.isAfter(now)) {
    return new restify.UnprocessableEntityError('Invalid time frame specified: to-date is in the future');
  }
  if (fromDate.isAfter(now)) {
    return new restify.UnprocessableEntityError('Invalid time frame specified: from-date is in the future');
  }

  if (fromDate.isAfter(toDate)) {
    return new restify.InvalidArgumentError(`Invalid time frame specified: from-date (${fromDate.format()}) is after to-date (${toDate.format()})`);
  }

  if (typeof noTimeLimit !== 'undefined' || noTimeLimit === false) {
    if (Math.abs(toDate.diff(fromDate, 'days')) > 31) {
      return new restify.InvalidArgumentError('Please choose a time frame up to 31 days maximum');
    }
  }
};
github phodal / freerice / server / service / rice_service.js View on Github external
Rice.prototype.create = function (req, res, next) {
    'use strict';

    var rice = req.params;

    if (serviceHelper.verifyRiceInput(rice)) {
        return next(new restify.InvalidArgumentError('String must be supplied'));
    }

    db.createRice(rice, function(result) {
        if (result.status === "success") {
            res.send({status: "success"});
            next();
        } else {
            result = _.extend(result, {status: "fail"});
            res.send(result);
            next();
        }
    });
};