Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ interface ChatCompletionResponse {
}

async function main(): Promise<void> {
const response = await fetch(chatCompletionsUrl(baseUrl), {
const endpoint = chatCompletionsUrl(baseUrl);
let response: Response;
try {
response = await fetch(endpoint, {
method: "POST",
headers: {
"content-type": "application/json",
Expand All @@ -162,9 +165,15 @@ async function main(): Promise<void> {
],
}),
});
} catch (error) {
const reason = error instanceof Error ? error.message : String(error);
throw new Error(
\`QVAC request failed at \${endpoint}. Is QVAC running? Check QVAC_BASE_URL. \${reason}\`,
);
}

if (!response.ok) {
throw new Error(\`QVAC request failed: \${response.status} \${response.statusText}\`);
throw new Error(\`QVAC request failed at \${endpoint}: \${response.status} \${response.statusText}\`);
}

const data = (await response.json()) as ChatCompletionResponse;
Expand Down
3 changes: 3 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ describe("create-qvac-app", () => {
expect(readFileSync(join(appDirectory, "src/index.ts"), "utf8")).toContain(
'normalized.endsWith("/v1")',
);
expect(readFileSync(join(appDirectory, "src/index.ts"), "utf8")).toContain(
"Is QVAC running? Check QVAC_BASE_URL",
);

const packageJson = JSON.parse(
readFileSync(join(appDirectory, "package.json"), "utf8"),
Expand Down
Loading