How to use the InvalidArgumentError function from restify

Find comprehensive JavaScript restify.InvalidArgumentError code examples handpicked from public code repositorys.

31
32
33
34
35
36
37
38
39
40

// PUT
server.put('/api/:id', function(req, res, next) {
   if (req.params.cost === undefined) {
      return next(new 
          restify.InvalidArgumentError('cost must be supplied'));
   }
   widget.update({_id: req.params.id, name: req.params.name, 
                  cost: req.params.cost},
     function (error, obj) {
fork icon60
star icon114
watch icon16

+ 47 other calls in file

262
263
264
265
266
267
268
269
270
271
异常处理代码

```{bash}
var server = restify.createServer();
server.get('/hello/:name', function(req, res, next) {
  return next(new restify.InvalidArgumentError("I just don't like you"));
});
```

运行程序
fork icon18
star icon42
watch icon7

+ 15 other calls in file

10
11
12
13
14
15
16
17
18
19

if (!req.params.user_id)
    return next(new restify.InvalidArgumentError('User ID required.'));

if (!req.params.rank || req.params.rank < 0 || req.params.rank > 10)
    return next(new restify.InvalidArgumentError('Rank required to be 0 to 10.'));

var trusted_auth = auth.get(req.params.auth.token);
if (trusted_auth === undefined) {
    return next(new restify.NotAuthorizedError('Bad auth token.'));
fork icon1
star icon1
watch icon5

+ 3 other calls in file

16
17
18
19
20
21
22
23
24
25
var restify = require('restify');

var resources = require('./resources');

var MissingParameterError = restify.MissingParameterError;
var InvalidArgumentError = restify.InvalidArgumentError;

function translate(rule) {
    var r = {
        id: rule.uuid,
fork icon24
star icon0
watch icon5

48
49
50
51
52
53
54
55
56

// --- Globals



var InvalidArgumentError  = restify.InvalidArgumentError;
var MissingParameterError = restify.MissingParameterError;
var ResourceNotFoundError = restify.ResourceNotFoundError;
var InternalError = restify.InternalError;
fork icon24
star icon0
watch icon1

155
156
157
158
159
160
161
162
163
164
    if (val && +val > 200 && (!ttl || +ttl < 1800)) {
      var msg = ''
        + 'Invalid param `pagesize`, value must be under `200`'
        + ' if no `ttl` was provided, or if `ttl` is less than `1800`'
        ;
      return new restify.InvalidArgumentError(msg);
    }
    return false;
  }
, notes: [
fork icon8
star icon15
watch icon12

+ 3 other calls in file

97
98
99
100
101
102
103
104
105
106
var errorHandler = function (e) {
  if (e) {
    console.error(e);
    next(e);
  }
  // if (e) return next(new restify.InvalidArgumentError(JSON.stringify(e.errors)));
}

var port = process.env.PORT || 8080;
server.listen(port, function () {
fork icon6
star icon1
watch icon2

323
324
325
326
327
328
329
330
331
332
 
@@ -49,38 +50,40 @@ Manifests.create = function (req, res, next) {
 
     if (params.version && !semver.valid(params.version)) {
         log.error({ version: params.version }, 'invalid version');
-        return (next(new restify.InvalidArgumentError(
-            'invalid version')));
+        next(new restify.InvalidArgumentError('invalid version'));
+        return;
     }
fork icon4
star icon0
watch icon0

+ 3 other calls in file

36
37
38
39
40
41
42
43
44
45
        'use strict';
        res.charSet('utf-8');
        if (req.query && Object.keys(req.query).length > 0) {
                routes.search(req.query, dataHandler(req, res, next));
        } else {
                return next(new restify.InvalidArgumentError('Params must be supplied'));
        }
});

server.get('/districts', list('districts'));
fork icon1
star icon8
watch icon9

+ 3 other calls in file

196
197
198
199
200
201
202
203
204
205
if (!(set in pkg_sets))
	return (next(new mod_restify.ResourceNotFoundError(
	    sprintf('no such package set: %s', set))));

if (search === null || search === undefined || search === '')
	return (next(new mod_restify.InvalidArgumentError(
	    sprintf('missing required search term'))));

ret = [];
search = search.toLowerCase();
fork icon0
star icon0
watch icon0

+ 2 other calls in file

15
16
17
18
19
20
21
22
23
24
  });
});

  server.post('/user', function (req, res, next) {
  if (req.params.name === undefined) {
    return next(new restify.InvalidArgumentError('Name must be supplied'))
  };
 
  userSave.create({ name: req.params.name }, function (error, user) {
    if (error) return next(new restify.InvalidArgumentError(JSON.stringify(error.errors)))
fork icon0
star icon0
watch icon7

+ 11 other calls in file

20
21
22
23
24
25
26
27
28
29
    ResourceNotFound: 404,
    WrongAccept: 406
};

function InvalidArgumentError(msg , outMsg){
    var error = new restify.InvalidArgumentError(msg);
    if(outMsg){
        error.body.outMsg = outMsg;
    }
    return error;
fork icon0
star icon0
watch icon0

+ 3 other calls in file