Skip to content

Commit

Permalink
cli: Report remote API specification download errors
Browse files Browse the repository at this point in the history
  • Loading branch information
karlvr committed Jul 29, 2024
1 parent 9005afb commit d534dbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/giant-keys-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-generator-plus": patch
---

Report remote API specification download errors
13 changes: 12 additions & 1 deletion packages/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ async function createCodegenInputPossiblyWithUrl(inputPathOrUrl: string): Promis

const startTime = Date.now()
const response = await fetch(inputPathOrUrl)
if (!response.ok) {
throw new Error(`Download failed with status ${response.status}: ${inputPathOrUrl}`)
}

const text = await response.text()
console.info(c.bold.green(`Downloaded in ${Date.now() - startTime}ms:`), inputPathOrUrl)

Expand All @@ -50,7 +54,14 @@ async function generate(config: CommandLineConfig, generatorConstructor: Codegen
const state = createCodegenState(config, generator)
state.log = log

const input = await createCodegenInputPossiblyWithUrl(config.inputPath)
let input: CodegenInputDocument
try {
input = await createCodegenInputPossiblyWithUrl(config.inputPath)
} catch (error) {
console.error(c.bold.red('Failed to get the API specification:'), error)
return false
}

let doc: CodegenDocument
try {
doc = createCodegenDocument(input, state)
Expand Down

0 comments on commit d534dbe

Please sign in to comment.