How to use the errors function from restify

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

147
148
149
150
151
152
153
154
155
156

// update note
note.save({data: params.data, hash: params.hash, updateTime: time}, function ( error ) {
    if ( error ) {
        debug(error);
        return callback(new restify.errors.InternalServerError('data saving failure'));
    }

    callback(null, true);
});
fork icon1
star icon5
watch icon3

+ 23 other calls in file

19
20
21
22
23
24
25
26
27
28

console.log('[REQUEST] %s:%s', controllerName, actionName);

if(actionConfig.visibility === MethodVisibility.PRIVATE) {
    if (!AuthController.getAuthUser(req))
    return next(new restify.errors.UnauthorizedError('You must be logged in to do this.'));
}

// Input validator
var validation = revalidator.validate(
fork icon1
star icon3
watch icon2

7
8
9
10
11
12
13
14
15
var escapeRE = require('escape-regexp-component');
var exec = require('child_process').exec;

var mime = require('mime');
var restify = require('restify');
var errors = restify.errors;

ALLOWED_EXTENSIONS = ['.nc','.g','.sbp','.gc','.gcode'];
ALLOWED_APP_EXTENSIONS = ['.zip', '.fma'];
fork icon22
star icon0
watch icon4

29
30
31
32
33
34
35
36
37
38
// Ensure only requests containing "Accept: application/json" headers
server.use((req, res, next) => {
    if (req.xhr || req.headers.hasOwnProperty('accept') && req.headers['accept'].indexOf('application/json') > -1) {
        return next();
    } else {
        return res.send(new restify.errors.MethodNotAllowedError((typeof err != 'undefined' ? err : "Method not allowed")))
    }
});

resolve(server);
fork icon1
star icon0
watch icon1

31
32
33
34
35
36
37
38
39
40
var match = req.body.toString().replace(/^data:([A-Za-z-+\/]+);base64/, '');
var imData = new Buffer(match, "base64");
fs.writeFile(newPath, imData, function (err) {
    if (err)
    {
        var err = new restify.errors.InternalServerError('image file could not be saved');
        res.send(err);
        return next();
    }
    else
fork icon0
star icon0
watch icon2

+ 3 other calls in file

29
30
31
32
33
34
35
36
37
38
if (hash !== verifyHash) {
  return next(new restify.errors.BadDigestError('x-signature does not match'))
}

if (typeof req.body['_source'] === 'undefined') {
  return next(new restify.errors.MissingParameterError('missing _source parameter in the json body'))
}
if (typeof req.body['_time'] === 'undefined') {
  return next(new restify.errors.MissingParameterError('missing _time parameter in the json body'))
}
fork icon0
star icon0
watch icon2

+ 9 other calls in file