internals.Policy.prototype.check = function () { if (!this._process.settings.sampleInterval) { return null; } Hoek.assert(this._process._eventLoopTimer, 'Cannot check load when sampler is not started'); var elapsed = this._process._loadBench.elapsed(); var load = this._process.load; if (elapsed > this._process.settings.sampleInterval) { load.eventLoopDelay = Math.max(load.eventLoopDelay, elapsed - this._process.settings.sampleInterval); } if (this.settings.maxEventLoopDelay && load.eventLoopDelay > this.settings.maxEventLoopDelay) { return Boom.serverTimeout('Server under heavy load (event loop)', load); } if (this.settings.maxHeapUsedBytes && load.heapUsed > this.settings.maxHeapUsedBytes) { return Boom.serverTimeout('Server under heavy load (heap)', load); } if (this.settings.maxRssBytes && load.rss > this.settings.maxRssBytes) { return Boom.serverTimeout('Server under heavy load (rss)', load); } return null; };
return function (req, res) { // Create request var request = new Request(self, req, res, options); // Check load if (limits.sampleInterval && ((limits.maxEventLoopDelay && (load.eventLoopDelay > limits.maxEventLoopDelay || self._loadBench.elapsed() > limits.maxEventLoopDelay)) || (limits.maxHeapUsedBytes && load.heapUsed > limits.maxHeapUsedBytes) || (limits.maxRssBytes && load.rss > limits.maxRssBytes))) { request._reply(Boom.serverTimeout('Server under heavy load', load)); } else { // Execute request lifecycle request._protect.domain.run(function () { request._execute(); }); } };
export function handleEsError(error) { if (!(error instanceof Error)) { throw new Error('Expected an instance of Error'); } const { reason, type } = get(error, 'body.error', {}); const details = { type }; if ( error instanceof ConnectionFault || error instanceof ServiceUnavailable || error instanceof NoConnections || error instanceof RequestTimeout ) { throw Boom.serverTimeout(); } if (error instanceof Conflict) { throw Boom.conflict(reason, details); } if (error instanceof Forbidden) { throw Boom.forbidden(reason, details); } if (error instanceof NotFound) { throw Boom.notFound(reason, details); } if (error instanceof BadRequest) { throw Boom.badRequest(reason, details); } throw error; }
getStations(function (err, stations) { if (err) { return reply(boom.internal()); } if (!stations[stationId]) { return reply(boom.notFound()); } var nowPlaying = state.getNowPlaying(stationId); if (!nowPlaying) { return reply(boom.serverTimeout('unavailable')); } reply(nowPlaying); });
app.server.methods.getTeachers(function (err, teachers) { if (err) { reply(Boom.serverTimeout(err)); } reply({ result: teachers, meta: { timestamp: moment().format() } }); });
app.server.methods.getSubjects(function (err, subjects) { if (err) { reply(Boom.serverTimeout(err)); } reply({ result: subjects, meta: { timestamp: moment().format() } }); });
return function (req, res) { // Create request var request = new Request(self, req, res, options); // Check load if (!self._load.check()) { self.server._log(['load'], self.server.load); request._reply(Boom.serverTimeout('Server under heavy load', self.server.load)); } else { // Execute request lifecycle request._protect.domain.run(function () { request._execute(); }); } };
module.exports = function handleESError(error) { if (!(error instanceof Error)) { throw new Error('Expected an instance of Error'); } if (error instanceof esErrors.ConnectionFault || error instanceof esErrors.ServiceUnavailable || error instanceof esErrors.NoConnections || error instanceof esErrors.RequestTimeout) { return Boom.serverTimeout(error); } else if (error instanceof esErrors.Conflict || _.contains(error.message, 'index_template_already_exists')) { return Boom.conflict(error); } else if (error instanceof esErrors[403]) { return Boom.forbidden(error); } else if (error instanceof esErrors.NotFound) { return Boom.notFound(error); } else if (error instanceof esErrors.BadRequest || error instanceof TypeError) { return Boom.badRequest(error); } else { return error; } };
}, function (err) { reply(Boom.serverTimeout(err)); });
const timeoutReply = () => { this._log(['request', 'server', 'timeout', 'error'], { timeout: serverTimeout, elapsed: this._bench.elapsed() }); this._reply(Boom.serverTimeout()); };
var timeoutReply = function () { self._log(['request', 'server', 'timeout', 'error'], { timeout: serverTimeout, elapsed: self._bench.elapsed() }); self._reply(Boom.serverTimeout()); };
setTimeout(function () { return finalize(id, Boom.serverTimeout(), null, null, report); }, this.rule.generateTimeout);
setTimeout(() => { return respond(this, id, Boom.serverTimeout(), null, null, report); }, this.rule.generateTimeout);
'53': function (err) { return Boom.serverTimeout('Database unavailable'); },
setTimeout(function () { return respond(self, id, Boom.serverTimeout(), null, null, report); }, this.rule.generateTimeout);
var timeoutReply = function () { self._reply(Boom.serverTimeout()); };
var timeoutReply = function () { self.log(['hapi', 'server', 'timeout']); self._reply(Boom.serverTimeout()); };