Skip to content

Commit

Permalink
Provide more info about where Hippo setup failed (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
itowlson authored Sep 14, 2021
1 parent a74320b commit 2e5ba6b
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions ts/generators/app/providers/hippo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,35 @@ export const hippo: Registry = {
try {
const { hippoUrl, hippoUsername, hippoPassword } = answers;
const agent = new https.Agent({ rejectUnauthorized: false });
const client = await HippoClient.new(hippoUrl, hippoUsername, hippoPassword, agent);
const appId = await client.createApplication(answers.moduleName, answers.bindleId);
await client.createChannel(appId, "Latest Release", "latest." + answers.domainName, { revisionRange: "*" });
await client.createChannel(appId, "Canary", "canary." + answers.domainName, { revisionRange: "P:*-canary-*" });
await client.createChannel(appId, `Development: ${user}`, `${user}.` + answers.domainName, { revisionRange: `P:*-${user}-*` });
const client = await withErrorContext("Login failed", () =>
HippoClient.new(hippoUrl, hippoUsername, hippoPassword, agent)
);
const appId = await withErrorContext("Application creation failed", () =>
client.createApplication(answers.moduleName, answers.bindleId)
);
await withErrorContext("Channel creation failed", async () => {
await client.createChannel(appId, "Latest Release", "latest." + answers.domainName, { revisionRange: "*" });
await client.createChannel(appId, "Canary", "canary." + answers.domainName, { revisionRange: "P:*-canary-*" });
await client.createChannel(appId, `Development: ${user}`, `${user}.` + answers.domainName, { revisionRange: `P:*-${user}-*` });
});
log(chalk.green('Setup complete'));
return undefined;
} catch (e) {
log(`${chalk.red('Setup failed!')} You will need to create the Hippo app manually.`);
log(`The error was: ${e}`);
return e;
return e as Error;
}
}
}

async function withErrorContext<T>(context: string, f: () => Promise<T>): Promise<T> {
try {
return await f();
} catch (e) {
throw new Error(`${context}: ${e}`);
}
}

function bindleise(user: string, app: string): string {
const ns = user.toLowerCase().replace(/[^a-zA-Z0-9-]/g, '');
const safeApp = app.toLowerCase().replace(/[^a-zA-Z0-9-]/g, '');
Expand Down

0 comments on commit 2e5ba6b

Please sign in to comment.