|
7 | 7 | workspace, |
8 | 8 | WorkspaceFolder, |
9 | 9 | } from "vscode"; |
| 10 | +import { RequestError } from "@octokit/request-error"; |
10 | 11 | import { |
11 | 12 | AbstractWebview, |
12 | 13 | WebviewPanelConfig, |
@@ -39,7 +40,7 @@ import { createDataExtensionYaml, loadDataExtensionYaml } from "./yaml"; |
39 | 40 | import { ExternalApiUsage } from "./external-api-usage"; |
40 | 41 | import { ModeledMethod } from "./modeled-method"; |
41 | 42 | import { ExtensionPackModelFile } from "./shared/extension-pack"; |
42 | | -import { autoModel } from "./auto-model-api"; |
| 43 | +import { autoModel, ModelRequest, ModelResponse } from "./auto-model-api"; |
43 | 44 | import { |
44 | 45 | createAutoModelRequest, |
45 | 46 | parsePredictedClassifications, |
@@ -421,7 +422,10 @@ export class DataExtensionsEditorView extends AbstractWebview< |
421 | 422 | message: "Sending request", |
422 | 423 | }); |
423 | 424 |
|
424 | | - const response = await autoModel(this.app.credentials, request); |
| 425 | + const response = await this.callApi(request); |
| 426 | + if (!response) { |
| 427 | + return; |
| 428 | + } |
425 | 429 |
|
426 | 430 | await this.showProgress({ |
427 | 431 | step: 2500, |
@@ -479,4 +483,19 @@ export class DataExtensionsEditorView extends AbstractWebview< |
479 | 483 | message: "", |
480 | 484 | }); |
481 | 485 | } |
| 486 | + |
| 487 | + private async callApi(request: ModelRequest): Promise<ModelResponse | null> { |
| 488 | + try { |
| 489 | + return await autoModel(this.app.credentials, request); |
| 490 | + } catch (e) { |
| 491 | + if (e instanceof RequestError && e.status === 429) { |
| 492 | + void showAndLogExceptionWithTelemetry( |
| 493 | + redactableError`Rate limit hit, please try again soon.`, |
| 494 | + ); |
| 495 | + return null; |
| 496 | + } else { |
| 497 | + throw e; |
| 498 | + } |
| 499 | + } |
| 500 | + } |
482 | 501 | } |
0 commit comments