How to use the boom.serverUnavailable function in boom

To help you get started, we’ve selected a few boom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codius / codiusd / src / services / HyperClient.ts View on Github external
console.log('waiting 5s to return from hyperclient createpod')
    await new Promise(resolve => {
      setTimeout(() => {
        console.log('waited 5s to return from hyperclient createpod')
        resolve()
      }, 5000)
    })
    if (res.data.Code !== 0) {
      console.log('waiting 5s to throw hyperclient')
      await new Promise(resolve => {
        setTimeout(() => {
          console.log('waited 5s to throw hyperclient')
          resolve()
        }, 5000)
      })
      throw Boom.serverUnavailable('Could not create pod: hyper error code=' + res.data.Code)
    }
    return res
  }
github sirensolutions / sentinl / server / routes / watcher_edit.js View on Github external
try {
        const body = JSON.parse(req.payload.query);
        log.debug('AVERAGE QUERY BODY:', JSON.stringify(body, null, 2));
        log.debug('INDEX:', esParams.index);

        const resp = await client.search({
          index: esParams.index,
          ignoreUnavailable: esParams.ignoreUnavailable,
          allowNoIndices: esParams.allowNoIndices,
          body,
        });

        return reply(resp);
      } catch (err) {
        return reply(Boom.serverUnavailable(err.message));
      }
    }
  });
github TheScienceMuseum / collectionsonline / routes / object.js View on Github external
if (responseType !== 'notAcceptable') {
        try {
          const result = await elastic.get({ index: 'smg', type: 'object', id: TypeMapping.toInternal(request.params.id) });

          const relatedItems = await getSimilarObjects(result, elastic);

          const sortedRelatedItems = sortRelated(relatedItems);
          const JSONData = buildJSONResponse(result, config, sortedRelatedItems);

          return response(h, JSONData, 'object', responseType);
        } catch (err) {
          if (err.status === 404) {
            return Boom.notFound(err);
          }
          return Boom.serverUnavailable('unavailable');
        }
      } else {
        return h.response('Not Acceptable').code(406);
      }
    }
  }
github eseom / hapi-react-fullstack-boilerplate / src / server / server.js View on Github external
handler: async (request, reply) => {
    const items = await getItems();
    if (items) {
      reply(items);
    } else {
      reply(Boom.serverUnavailable('Widget load fails 33% of the time. You were unlucky.', {}));
    }
  },
  config: {
github elastic / kibana / src / legacy / core_plugins / elasticsearch / lib / handle_es_error.js View on Github external
export 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.serverUnavailable(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) {
    return Boom.badRequest(error);
  } else {
    return error;
  }
}
github TheScienceMuseum / collectionsonline / routes / iiif.js View on Github external
try {
        const result = await elastic.get({ index: 'smg', type: TypeMapping.toInternal(request.params.type), id: TypeMapping.toInternal(request.params.id) });

        var iiifData = buildJSONResponse(result, config);
        iiifData.self = config.rootUrl + '/iiif/' + iiifData.data.type + '/' + iiifData.data.id;

        return h.response(
          Handlebars.compile(
            fs.readFileSync(path.join(__dirname, '/../templates/iiif/iiifmanifest.json'), 'utf8')
          )(iiifData)
        ).header('content-type', 'application/json');
      } catch (err) {
        if (err.status === 404) {
          return Boom.notFound();
        }
        return Boom.serverUnavailable('unavailable');
      }
    }
  }
github ozum / joi18n / node_modules / hapi / node_modules / heavy / lib / index.js View on Github external
if (this.settings.maxEventLoopDelay &&
        load.eventLoopDelay > this.settings.maxEventLoopDelay) {

        throw Boom.serverUnavailable('Server under heavy load (event loop)', load);
    }

    if (this.settings.maxHeapUsedBytes &&
        load.heapUsed > this.settings.maxHeapUsedBytes) {

        throw Boom.serverUnavailable('Server under heavy load (heap)', load);
    }

    if (this.settings.maxRssBytes &&
        load.rss > this.settings.maxRssBytes) {

        throw Boom.serverUnavailable('Server under heavy load (rss)', load);
    }
};
github brave-intl / bat-ledger / ledger / controllers / registrar.js View on Github external
const viewings = runtime.database.get('viewings', debug)
    let diagnostic, surveyorIds, viewing

    viewing = await viewings.findOne({ uId: uId })
    if (!viewing) {
      throw boom.notFound('viewingId not valid: ' + uId)
    }

    surveyorIds = viewing.surveyorIds || []
    if (surveyorIds.length !== viewing.count) {
      diagnostic = 'surveyorIds invalid found ' + surveyorIds.length + ', expecting ' + viewing.count +
                   ', surveyorId=' + viewing.surveyorId
      runtime.captureException(diagnostic, { req: request, extra: { viewing: uId } })

      const resp = boom.serverUnavailable(diagnostic)
      resp.output.headers['retry-after'] = '5'
      throw resp
    }
    underscore.extend(response, { surveyorIds: viewing.surveyorIds })

    try {
      verification = registrar.register(proof)
    } catch (ex) {
      throw boom.badData('invalid registrar proof: ' + JSON.stringify(proof))
    }

    state = { $currentDate: { timestamp: { $type: 'timestamp' } } }
    await credentials.update({ uId: uId, registrarId: registrar.registrarId }, state, { upsert: true })

    return underscore.extend(response, { verification })
  }
github ozum / joi18n / node_modules / hapi / node_modules / heavy / lib / index.js View on Github external
const load = this.load;

    if (elapsed > this.settings.sampleInterval) {
        load.eventLoopDelay = Math.max(load.eventLoopDelay, elapsed - this.settings.sampleInterval);
    }

    if (this.settings.maxEventLoopDelay &&
        load.eventLoopDelay > this.settings.maxEventLoopDelay) {

        throw Boom.serverUnavailable('Server under heavy load (event loop)', load);
    }

    if (this.settings.maxHeapUsedBytes &&
        load.heapUsed > this.settings.maxHeapUsedBytes) {

        throw Boom.serverUnavailable('Server under heavy load (heap)', load);
    }

    if (this.settings.maxRssBytes &&
        load.rss > this.settings.maxRssBytes) {

        throw Boom.serverUnavailable('Server under heavy load (rss)', load);
    }
};
github eseom / hapi-react-fullstack-boilerplate / src / server / items / api.js View on Github external
}, async (request, reply) => {
  const items = await getItems()
  if (items) {
    reply(items)
  } else {
    reply(Boom.serverUnavailable('Widget load fails 33% of the time. You were unlucky.', {}))
  }
})