How to use the ServiceUnavailableError function from restify

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

168
169
170
171
172
173
174
175
176
177

// Return Service Unavailable if backend is not connected
server.use(function ensureBackendConnected(req, res, next) {
    if (typeof (backend.connected) !== 'undefined' &&
        backend.connected === false) {
        return next(new restify.ServiceUnavailableError(
            'Backend not connected'));
    }

    return next();
fork icon71
star icon449
watch icon0

21
22
23
24
25
26
27
28
29
30
/*
 * Checks that WFAPI workflows are loaded.
 */
exports.checkWfapi = function checkWfapi(req, res, next) {
    if (!req.app.wfapi.connected) {
        return next(new restify.ServiceUnavailableError('Workflow API is ' +
            'unavailable'));
    }
    return next();
};
fork icon20
star icon11
watch icon35

144
145
146
147
148
149
150
151
152
    next();
    return;
}

if (self.draining) {
    next(new restify.ServiceUnavailableError(
        'CN Agent is not accepting tasks for maintenance'));
    return;
}
fork icon17
star icon0
watch icon1

220
221
222
223
224
225
226
227
228
229
+function ensureMasterConfigLoaded(req, res, next) {
+    var model = this.model;
+
+    if (req.params.include_master) {
+        if (typeof (model.config.moray.master_host) === 'undefined') {
+            next(new restify.ServiceUnavailableError(
+                'Parameter \'include_master\' has been specified but ' +
+                'this SAPI instance has not yet loaded master details'));
+            return;
+        }
fork icon4
star icon0
watch icon0

35
36
37
38
39
40
41
42
43
44

var throttle = whyyoulittle.createThrottle({
    concurrency: 2,
    queueTolerance: 2,
    createThrottledError:  function create503(throttle, req) {
        return new restify.ServiceUnavailableError('request throttled');
    }
})

server.use(restify.requestLogger());
fork icon2
star icon2
watch icon34

27
28
29
30
31
32
33
34
35
36

toobusy: function(req, res, next)
{
    if (toobusy())
    {
        next(new restify.ServiceUnavailableError('The server is too busy right now'));
    }
    else
    {
        next();
fork icon1
star icon17
watch icon2

33
34
35
36
37
38
39
40
41
42
QueryExecutor.prototype = (function () {

    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

5
6
7
8
9
10
11
12
13

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

18
19
20
21
22
23
24
25
26
27
server.on('uncaughtException', (req, res, route, err) => {
    log.error(err);
    if (res._header) {
        res.end();
    } else {
        res.send(new restify.ServiceUnavailableError());
    }
});

server.pre(({body, url}, res, next) => {
fork icon0
star icon0
watch icon0