|
6 | 6 | window, |
7 | 7 | workspace, |
8 | 8 | } from "vscode"; |
| 9 | +import { RequestError } from "@octokit/request-error"; |
9 | 10 | import { |
10 | 11 | AbstractWebview, |
11 | 12 | WebviewPanelConfig, |
@@ -38,7 +39,7 @@ import { createDataExtensionYaml, loadDataExtensionYaml } from "./yaml"; |
38 | 39 | import { ExternalApiUsage } from "./external-api-usage"; |
39 | 40 | import { ModeledMethod } from "./modeled-method"; |
40 | 41 | import { ExtensionPackModelFile } from "./shared/extension-pack"; |
41 | | -import { autoModel } from "./auto-model-api"; |
| 42 | +import { autoModel, ModelRequest, ModelResponse } from "./auto-model-api"; |
42 | 43 | import { |
43 | 44 | createAutoModelRequest, |
44 | 45 | parsePredictedClassifications, |
@@ -401,7 +402,10 @@ export class DataExtensionsEditorView extends AbstractWebview< |
401 | 402 | message: "Sending request", |
402 | 403 | }); |
403 | 404 |
|
404 | | - const response = await autoModel(this.app.credentials, request); |
| 405 | + const response = await this.callAutoModelApi(request); |
| 406 | + if (!response) { |
| 407 | + return; |
| 408 | + } |
405 | 409 |
|
406 | 410 | await this.showProgress({ |
407 | 411 | step: 2500, |
@@ -459,4 +463,23 @@ export class DataExtensionsEditorView extends AbstractWebview< |
459 | 463 | message: "", |
460 | 464 | }); |
461 | 465 | } |
| 466 | + |
| 467 | + private async callAutoModelApi( |
| 468 | + request: ModelRequest, |
| 469 | + ): Promise<ModelResponse | null> { |
| 470 | + try { |
| 471 | + return await autoModel(this.app.credentials, request); |
| 472 | + } catch (e) { |
| 473 | + await this.clearProgress(); |
| 474 | + |
| 475 | + if (e instanceof RequestError && e.status === 429) { |
| 476 | + void showAndLogExceptionWithTelemetry( |
| 477 | + redactableError(e)`Rate limit hit, please try again soon.`, |
| 478 | + ); |
| 479 | + return null; |
| 480 | + } else { |
| 481 | + throw e; |
| 482 | + } |
| 483 | + } |
| 484 | + } |
462 | 485 | } |
0 commit comments