const checkIfElasticSearchIsNotAvailable = (error) => { if (error && esIsDisconnectedMessage.test(error.message)) { throw Boom.boomify(error, {statusCode: 502}) } // do not manage anything else }
function renderAndReply (template, context, reply) { const TemplatePath = Path.resolve(__dirname, '..', 'views', `${template}.html`) const app = new Vue({ data: context, template: Fs.readFileSync(TemplatePath, 'utf-8') }) return Renderer.renderToString(app, (err, html) => { if (err) { console.log(err) return reply(Boom.boomify(err, { statusCode: 500 })) } return reply(html) }) }
const checkIfElasticSearchHasAConflict = (error) => { if (error && error.body && error.body.error && error.body.error.type === 'resource_already_exists_exception') { // already exists => conflict ! HTTP 409 throw Boom.boomify(error, {statusCode: 409}) } // do not manage anything else }
const getWeatherByCityName = async function (req, res) { const cityName = req.query.cityName try { const data = await weatherCtrl.getWeatherByCityName(cityName) return res({ name: data.name, coord: data.coord, weather: data.weather }) } catch (error) { const errorMessage = `Failed to fetch weather for ${cityName}` !error.logged && logger.error(error, errorMessage) return res(boom.boomify(error, { statusCode: httpStatus.INTERNAL_SERVER_ERROR, message: errorMessage })) } }
error: e }; const error = boom.boomify(e, {statusCode: 429}); error.output.payload.message = settings.message; throw error;
throw boom.boomify(err, {statusCode: 599, message: `Error while calling API ${id}: ${err.message}`})
error: e }; const error = boom.boomify(e, {statusCode: 429}); error.output.payload.message = settings.message; throw error;