fix(core): prioritize detailed error messages for code assist setup (#17852)

This commit is contained in:
Gaurav
2026-02-02 20:27:55 -08:00
committed by GitHub
parent 5b254c379c
commit 1b274b081d
3 changed files with 50 additions and 8 deletions

View File

@@ -7,6 +7,7 @@
import type {
ClientMetadata,
GeminiUserTier,
IneligibleTier,
LoadCodeAssistResponse,
OnboardUserRequest,
} from './types.js';
@@ -35,6 +36,16 @@ export class ValidationCancelledError extends Error {
}
}
export class IneligibleTierError extends Error {
readonly ineligibleTiers: IneligibleTier[];
constructor(ineligibleTiers: IneligibleTier[]) {
const reasons = ineligibleTiers.map((t) => t.reasonMessage).join(', ');
super(reasons);
this.ineligibleTiers = ineligibleTiers;
}
}
export interface UserData {
projectId: string;
userTier: UserTierId;
@@ -127,13 +138,7 @@ export async function setupUser(
}
// If user is not setup for standard tier, inform them about all other tiers they are ineligible for.
if (loadRes.ineligibleTiers && loadRes.ineligibleTiers.length > 0) {
const reasons = loadRes.ineligibleTiers
.map((t) => t.reasonMessage)
.join(', ');
throw new Error(reasons);
}
throw new ProjectIdRequiredError();
throwIneligibleOrProjectIdError(loadRes);
}
return {
projectId: loadRes.cloudaicompanionProject,
@@ -180,7 +185,8 @@ export async function setupUser(
userTierName: tier.name,
};
}
throw new ProjectIdRequiredError();
throwIneligibleOrProjectIdError(loadRes);
}
return {
@@ -190,6 +196,13 @@ export async function setupUser(
};
}
function throwIneligibleOrProjectIdError(res: LoadCodeAssistResponse): never {
if (res.ineligibleTiers && res.ineligibleTiers.length > 0) {
throw new IneligibleTierError(res.ineligibleTiers);
}
throw new ProjectIdRequiredError();
}
function getOnboardTier(res: LoadCodeAssistResponse): GeminiUserTier {
for (const tier of res.allowedTiers || []) {
if (tier.isDefault) {