How to use the BadRequestError function from restify

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

36
37
38
39
40
41
42
43
44
let employeeId = req.params.employeeId;

let pictureType = req.query.pictureType || '1';

if (!employeeId) {
    res.send(new restify.BadRequestError('Invalid employee id'));
    next();
    return;
}
fork icon69
star icon95
watch icon21

236
237
238
239
240
241
242
243
244
/*
 * Restify handler for handling form uploads.
 */
function upload(request, response, next)
{
        next(new mod_restify.BadRequestError('Unauthorized'));
}

main();
fork icon8
star icon77
watch icon12

+ 3 other calls in file

35
36
37
38
39
40
41
42
43
var errorHandling = function (err) {
    log.error(err);
    if (err.fatal) {
        return new restify.ServiceUnavailableError('Database Fatal Error: ' + err.code);
    } else if (err.code === 'ER_DUP_ENTRY') {
        return new restify.BadRequestError('Request can not accomplished, cause of duplicate entrys in the database');
    }
    return new restify.UnprocessableEntityError('Database query failed: ' + err.code);
};
fork icon1
star icon2
watch icon2

+ 3 other calls in file

4
5
6
7
8
9
10
11
12
13
'use strict';

const restify = require('restify');
const snakeCase = require('snake-case');

const BadRequest = restify.BadRequestError;
const ServiceUnavailable = restify.ServiceUnavailableError;

const Router = require('../utils/route.js');
const router = new Router();
fork icon0
star icon1
watch icon2

74
75
76
77
78
79
80
81
82
  res.write(body);
  return res.end();
});

router.post('/user', (req, res) => {
  if (!req.params.username || !req.params.password || !req.params.email) return res.send(new restify.BadRequestError('Missing username and/or password and/or email'));

  bcrypt.hash(req.params.password, 8, async (err, hash) => {
    if (err) return res.send(new restify.InternalServerError('Internal server error'));
fork icon0
star icon1
watch icon2

+ 3 other calls in file

208
209
210
211
212
213
214
215
216
217
  }

  if (typeof req.params['sensorId'] !== 'undefined') {
    let sensorId = req.params['sensorId'].toString();
    if (sensorId && !mongoose.Types.ObjectId.isValid(sensorId)) {
      next(new restify.BadRequestError('Parameter :sensorId is not valid'));
    }
  }
  next();
});
fork icon36
star icon0
watch icon0

+ 3 other calls in file