Skip to content

Commit 134c440

Browse files
authored
Handle 429 from auto-model service (#2474)
1 parent 7250e82 commit 134c440

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-view.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
window,
77
workspace,
88
} from "vscode";
9+
import { RequestError } from "@octokit/request-error";
910
import {
1011
AbstractWebview,
1112
WebviewPanelConfig,
@@ -38,7 +39,7 @@ import { createDataExtensionYaml, loadDataExtensionYaml } from "./yaml";
3839
import { ExternalApiUsage } from "./external-api-usage";
3940
import { ModeledMethod } from "./modeled-method";
4041
import { ExtensionPackModelFile } from "./shared/extension-pack";
41-
import { autoModel } from "./auto-model-api";
42+
import { autoModel, ModelRequest, ModelResponse } from "./auto-model-api";
4243
import {
4344
createAutoModelRequest,
4445
parsePredictedClassifications,
@@ -401,7 +402,10 @@ export class DataExtensionsEditorView extends AbstractWebview<
401402
message: "Sending request",
402403
});
403404

404-
const response = await autoModel(this.app.credentials, request);
405+
const response = await this.callAutoModelApi(request);
406+
if (!response) {
407+
return;
408+
}
405409

406410
await this.showProgress({
407411
step: 2500,
@@ -459,4 +463,23 @@ export class DataExtensionsEditorView extends AbstractWebview<
459463
message: "",
460464
});
461465
}
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+
}
462485
}

0 commit comments

Comments
 (0)