Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err);
reply(
Boom.badGateway('Internal error', err)
);
});
}
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'));
});
}
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
};
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);
});
}).catch((err) => {
if (err.status === 404) {
reply(Boom.notFound('Organisation not found.', err));
} else {
reply(Boom.badGateway('Error accessing OpenTrials API.', err));
}
});
}
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) }
}).catch((err) => {
if (err.status === 404) {
reply(Boom.notFound('Person not found.', err));
} else {
reply(Boom.badGateway('Error accessing OpenTrials API.', err));
}
});
}
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);
}
}
};
}).catch((err) => {
if (err.status === 404) {
reply(Boom.notFound('Condition not found.', err));
} else {
reply(Boom.badGateway('Error accessing OpenTrials API.', err));
}
});
}
)).catch((err) => (
reply(Boom.badGateway('Error accessing OpenTrials API.', err))
));
}