From 61f34055fa75e58771e7b3f38bec14de1acb5f40 Mon Sep 17 00:00:00 2001 From: Oleg Demchenko Date: Thu, 10 Jun 2021 13:14:08 -0700 Subject: [PATCH] Auth session API fix (#125792) * Adjust "provider is not registered" exception behavior * Process cancellation in GH auth provider `e.message` is always `undefined` --- extensions/github-authentication/src/github.ts | 2 +- .../authentication/browser/authenticationService.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/extensions/github-authentication/src/github.ts b/extensions/github-authentication/src/github.ts index 504af0384d6..cf0b65424e6 100644 --- a/extensions/github-authentication/src/github.ts +++ b/extensions/github-authentication/src/github.ts @@ -209,7 +209,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid return session; } catch (e) { // If login was cancelled, do not notify user. - if (e.message === 'Cancelled') { + if (e === 'Cancelled') { /* __GDPR__ "loginCancelled" : { } */ diff --git a/src/vs/workbench/services/authentication/browser/authenticationService.ts b/src/vs/workbench/services/authentication/browser/authenticationService.ts index 8652c0c8dd2..07fe8663867 100644 --- a/src/vs/workbench/services/authentication/browser/authenticationService.ts +++ b/src/vs/workbench/services/authentication/browser/authenticationService.ts @@ -713,19 +713,19 @@ export class AuthenticationService extends Disposable implements IAuthentication } async getSessions(id: string, scopes?: string[], activateImmediate: boolean = false): Promise> { - try { - const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate); + const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate); + if (authProvider) { return await authProvider.getSessions(scopes); - } catch (_) { + } else { throw new Error(`No authentication provider '${id}' is currently registered.`); } } async createSession(id: string, scopes: string[], activateImmediate: boolean = false): Promise { - try { - const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate); + const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate); + if (authProvider) { return await authProvider.createSession(scopes); - } catch (_) { + } else { throw new Error(`No authentication provider '${id}' is currently registered.`); } }