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) {
60
114
16
+ 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")); }); ``` 运行程序
18
42
7
+ 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.'));
1
1
5
+ 3 other calls in file
GitHub: eait-itig/sdc-cloudapi
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,
24
0
5
GitHub: misterdjules/sdc-cloudapi
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;
24
0
1
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: [
8
15
12
+ 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 () {
6
1
2
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; }
4
0
0
+ 3 other calls in file
GitHub: openleb/nouwweb
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'));
1
8
9
+ 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();
0
0
0
+ 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)))
0
0
7
+ 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;
0
0
0
+ 3 other calls in file
restify.createServer is the most popular function in restify (1059 examples)