Skip to content

Commit

Permalink
fix: datasets: handle error responses
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <[email protected]>
  • Loading branch information
g-linville committed Oct 14, 2024
1 parent 96d3724 commit b109bdf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ export class GPTScript {
const r: Run = new RunSubcommand("datasets", "", {URL: this.opts.URL, Token: this.opts.Token})
r.request({input: "{}", workspace: workspace, datasetToolRepo: this.opts.DatasetToolRepo ?? ""})
const result = await r.text()
if (result.startsWith("ERROR:")) {
throw new Error(result)
}
return JSON.parse(result) as Array<DatasetMeta>
}

Expand All @@ -416,6 +419,9 @@ export class GPTScript {
datasetToolRepo: this.opts.DatasetToolRepo ?? ""
})
const result = await r.text()
if (result.startsWith("ERROR:")) {
throw new Error(result)
}
return JSON.parse(result) as Dataset
}

Expand All @@ -436,6 +442,9 @@ export class GPTScript {
datasetToolRepo: this.opts.DatasetToolRepo ?? ""
})
const result = await r.text()
if (result.startsWith("ERROR:")) {
throw new Error(result)
}
return JSON.parse(result) as DatasetElementMeta
}

Expand All @@ -451,6 +460,9 @@ export class GPTScript {
datasetToolRepo: this.opts.DatasetToolRepo ?? ""
})
const result = await r.text()
if (result.startsWith("ERROR:")) {
throw new Error(result)
}
return JSON.parse(result) as Array<DatasetElementMeta>
}

Expand All @@ -466,6 +478,9 @@ export class GPTScript {
datasetToolRepo: this.opts.DatasetToolRepo ?? ""
})
const result = await r.text()
if (result.startsWith("ERROR:")) {
throw new Error(result)
}
return JSON.parse(result) as DatasetElement
}

Expand Down

0 comments on commit b109bdf

Please sign in to comment.