Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getBest (appId, orgaId) {
Logger.debug('Trying to get the favourite vhost for ' + appId);
return getFavouriteDomain({ id: orgaId, appId }).then(sendToApi)
.catch(async (e) => {
if (e.status !== 404) {
throw e;
}
Logger.debug('No favourite vhost defined for ' + appId + ', selecting the best one');
const allDomains = await getAllDomains({ id: orgaId, appId }).then(sendToApi);
const result = selectBest(allDomains);
if (result == null) {
throw new Error(`Couldn't find a domain name`);
}
return result;
});