How to use the UnprocessableEntityError function from restify

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

37
38
39
40
41
42
43
44
45
46
    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);
};

function getPool() {
    return this.pool;
fork icon1
star icon2
watch icon2

45
46
47
48
49
50
51
52
53
    return next();
  }
  // bad data -> 422 UnprocessableEntityError
  log.warn('bad data schema -> %s', JSON.stringify(req.body));
  return next(
    new restify.UnprocessableEntityError(
      config.UNPROCESSABLE_ENTITY_ERROR_MESSAGE));
}

fork icon0
star icon1
watch icon3

12
13
14
15
16
17
18
19
20
21

var data;
try {
  data = JSON.parse(req.query.data);
} catch(e) {
  return next(new restify.UnprocessableEntityError('Bad Request: malformed JSON in `data` query parameter'));
}

if(!data.organization || !data.organization.id) {
  return next(new restify.InvalidCredentialsError('Bad Request: missing organization id'));
fork icon1
star icon0
watch icon11

50
51
52
53
54
55
56
57
58
59
  console.log('this one is not valid, sending 422', req.body)
  // bad data -> 422 UnprocessableEntityError
  var msg = 'Invalid post schema.'
  emitter.emit('error', msg)
  return next(
    new restify.UnprocessableEntityError(msg))
}

module.exports = function (port, cb) {
  var server = restify.createServer()
fork icon0
star icon1
watch icon2