How to use the boom.badGateway 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 opentrials / opentrials / handlers / data.js View on Github external
.catch((err) => {
      // eslint-disable-next-line no-console
      console.error(err);
      reply(
        Boom.badGateway('Internal error', err)
      );
    });
}
github eseom / hapi-react-fullstack-boilerplate / src / server / core / plugins / hapi-async-route / index.js View on Github external
p.catch((e) => {
              console.error(e.stack);  // eslint-disable-line no-console
              console.error(e.toString()); // eslint-disable-line no-console
              reply(Boom.badGateway('server error'));
            });
          }
github hapijs / hapi / lib / client.js View on Github external
if (redirects === false ||
            [301, 302, 307, 308].indexOf(res.statusCode) === -1) {

            return finish(null, res);
        }

        // Redirection

        var redirectMethod = (res.statusCode === 301 || res.statusCode === 302 ? 'GET' : uri.method);
        var location = res.headers.location;

        res.destroy();

        if (redirects === 0) {
            return finish(Boom.badGateway('Maximum redirections reached', _trace));
        }

        if (!location) {
            return finish(Boom.badGateway('Received redirection without location', _trace));
        }

        if (!location.match(/^https?:/i)) {
            location = Url.resolve(uri.href, location);
        }

        var redirectOptions = {
            headers: options.headers,
            payload: shadow || options.payload,         // shadow must be ready at this point if set
            redirects: --redirects
        };
github hapijs / hapi / lib / client.js View on Github external
return finish(null, res);
        }

        // Redirection

        var redirectMethod = (res.statusCode === 301 || res.statusCode === 302 ? 'GET' : uri.method);
        var location = res.headers.location;

        res.destroy();

        if (redirects === 0) {
            return finish(Boom.badGateway('Maximum redirections reached', _trace));
        }

        if (!location) {
            return finish(Boom.badGateway('Received redirection without location', _trace));
        }

        if (!location.match(/^https?:/i)) {
            location = Url.resolve(uri.href, location);
        }

        var redirectOptions = {
            headers: options.headers,
            payload: shadow || options.payload,         // shadow must be ready at this point if set
            redirects: --redirects
        };

        exports.request(redirectMethod, location, redirectOptions, finish, _trace);
    });
github opentrials / opentrials / handlers / organisation.js View on Github external
}).catch((err) => {
    if (err.status === 404) {
      reply(Boom.notFound('Organisation not found.', err));
    } else {
      reply(Boom.badGateway('Error accessing OpenTrials API.', err));
    }
  });
}
github brave-intl / bat-ledger / ledger / controllers / grants.js View on Github external
return async (request, h) => {
    if (runtime.config.disable.grants) {
      throw boom.serverUnavailable()
    }
    const { paymentId } = request.query

    if (!runtime.config.wreck.grants.baseUrl) {
      throw boom.badGateway('not configured for promotions')
    }

    const platform = protocolVersion === 3 ? 'android' : 'desktop'

    const { grants } = runtime.config.wreck
    const payload = await braveHapi.wreck.get(grants.baseUrl + '/v1/promotions?legacy=true&paymentId=' + (paymentId || '') + '&platform=' + platform, {
      headers: grants.headers,
      useProxyP: true
    })
    const promotions = JSON.parse(payload.toString()).promotions

    const adsAvailable = await adsGrantsAvailable(request.headers['fastly-geoip-countrycode'])

    const filteredPromotions = []
    for (let { id, type, platform } of promotions) {
      const promotion = { promotionId: id, type: legacyTypeFromTypeAndPlatform(type, platform) }
github opentrials / opentrials / handlers / person.js View on Github external
}).catch((err) => {
    if (err.status === 404) {
      reply(Boom.notFound('Person not found.', err));
    } else {
      reply(Boom.badGateway('Error accessing OpenTrials API.', err));
    }
  });
}
github mdibaiee / hapi-sequelize-crud / src / error.js View on Github external
let err;

        if (e.name === 'SequelizeValidationError')
          err = Boom.badData(message);
        else if (e.name === 'SequelizeConnectionTimedOutError')
          err = Boom.gatewayTimeout(message);
        else if (e.name === 'SequelizeHostNotReachableError')
          err = Boom.serverUnavailable(message);
        else if (e.name === 'SequelizeUniqueConstraintError')
          err = Boom.conflict(message);
        else if (e.name === 'SequelizeForeignKeyConstraintError')
          err = Boom.expectationFailed(message);
        else if (e.name === 'SequelizeExclusionConstraintError')
          err = Boom.expectationFailed(message);
        else if (e.name === 'SequelizeConnectionError')
          err = Boom.badGateway(message);
        else err = Boom.badImplementation(message);

        reply(err);
      } else {
        reply(e);
      }
    }
  };
github opentrials / opentrials / handlers / condition.js View on Github external
}).catch((err) => {
    if (err.status === 404) {
      reply(Boom.notFound('Condition not found.', err));
    } else {
      reply(Boom.badGateway('Error accessing OpenTrials API.', err));
    }
  });
}
github opentrials / opentrials / handlers / terms-of-use.js View on Github external
)).catch((err) => (
    reply(Boom.badGateway('Error accessing OpenTrials API.', err))
  ));
}