Skip to content

Commit a09be5d

Browse files
authored
1 parent e678c2e commit a09be5d

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/vs/workbench/contrib/chat/browser/chatSetup.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ class ChatSetupRequests extends Disposable {
574574
return this.resolveEntitlement(session, CancellationToken.None);
575575
}
576576

577-
async signUpLimited(session: AuthenticationSession): Promise<boolean> {
577+
async signUpLimited(session: AuthenticationSession): Promise<true /* signed up */ | false /* already signed up */ | undefined /* error */> {
578578
const body = {
579579
restricted_telemetry: this.telemetryService.telemetryLevel === TelemetryLevel.NONE ? 'disabled' : 'enabled',
580580
public_code_suggestions: 'enabled'
@@ -583,7 +583,7 @@ class ChatSetupRequests extends Disposable {
583583
const response = await this.request(defaultChat.entitlementSignupLimitedUrl, 'POST', body, session, CancellationToken.None);
584584
if (!response) {
585585
this.onUnknownSignUpError('[chat setup] sign-up: no response');
586-
return false;
586+
return undefined;
587587
}
588588

589589
if (response.res.statusCode && response.res.statusCode !== 200) {
@@ -594,15 +594,15 @@ class ChatSetupRequests extends Disposable {
594594
const responseError: { message: string } = JSON.parse(responseText);
595595
if (typeof responseError.message === 'string' && responseError.message) {
596596
this.onUnprocessableSignUpError(`[chat setup] sign-up: unprocessable entity (${responseError.message})`, responseError.message);
597-
return false;
597+
return undefined;
598598
}
599599
}
600600
} catch (error) {
601601
// ignore - handled below
602602
}
603603
}
604604
this.onUnknownSignUpError(`[chat setup] sign-up: unexpected status code ${response.res.statusCode}`);
605-
return false;
605+
return undefined;
606606
}
607607

608608
let responseText: string | null = null;
@@ -614,7 +614,7 @@ class ChatSetupRequests extends Disposable {
614614

615615
if (!responseText) {
616616
this.onUnknownSignUpError('[chat setup] sign-up: response has no content');
617-
return false;
617+
return undefined;
618618
}
619619

620620
let parsedResult: { subscribed: boolean } | undefined = undefined;
@@ -623,20 +623,14 @@ class ChatSetupRequests extends Disposable {
623623
this.logService.trace(`[chat setup] sign-up: response is ${responseText}`);
624624
} catch (err) {
625625
this.onUnknownSignUpError(`[chat setup] sign-up: error parsing response (${err})`);
626+
return undefined;
626627
}
627628

628-
const subscribed = Boolean(parsedResult?.subscribed);
629-
if (subscribed) {
630-
this.logService.trace('[chat setup] sign-up: successfully subscribed');
631-
} else {
632-
this.logService.error('[chat setup] sign-up: not subscribed');
633-
}
634-
635-
if (subscribed) {
636-
this.update({ entitlement: ChatEntitlement.Limited });
637-
}
629+
// We have made it this far, so the user either did sign-up or was signed-up already.
630+
// That is, because the endpoint throws in all other case according to Patrick.
631+
this.update({ entitlement: ChatEntitlement.Limited });
638632

639-
return subscribed;
633+
return Boolean(parsedResult?.subscribed);
640634
}
641635

642636
private onUnknownSignUpError(logMessage: string): void {
@@ -824,14 +818,14 @@ class ChatSetupController extends Disposable {
824818

825819
let installResult: 'installed' | 'cancelled' | 'failedInstall' | undefined = undefined;
826820
const wasInstalled = this.context.state.installed;
827-
let didSignUp = false;
821+
let didSignUp: boolean | undefined = undefined;
828822
try {
829823
showCopilotView(this.viewsService, this.layoutService);
830824

831825
if (entitlement !== ChatEntitlement.Limited && entitlement !== ChatEntitlement.Pro && entitlement !== ChatEntitlement.Unavailable) {
832826
didSignUp = await this.requests.signUpLimited(session);
833827

834-
if (!didSignUp) {
828+
if (typeof didSignUp === 'undefined' /* error */) {
835829
this.telemetryService.publicLog2<InstallChatEvent, InstallChatClassification>('commandCenter.chatInstall', { installResult: 'failedSignUp', signedIn });
836830
}
837831
}

0 commit comments

Comments
 (0)