in packages/core/src/login/webview/vue/backend.ts [88:161]
async ssoSetup(methodName: string, setupFunc: () => Promise<any>, postMetrics: boolean = true) {
const runSetup = async () => {
try {
await setupFunc()
return
} catch (e) {
getLogger().error('ssoSetup encountered an error: %s', e)
if (e instanceof ToolkitError && e.code === 'NotOnboarded') {
/**
* Connection is fine, they just skipped onboarding so not an actual error.
*
* The error comes from user cancelling prompt by {@link CodeCatalystAuthenticationProvider.promptOnboarding()}
*/
return
}
if (
CancellationError.isUserCancelled(e) ||
(e instanceof ToolkitError && (CancellationError.isUserCancelled(e.cause) || e.cancelled === true))
) {
return { id: userCancelled, text: 'Setup cancelled.' }
}
if (e instanceof ToolkitError && e.cause instanceof InvalidGrantException) {
return {
id: 'invalidGrantException',
text: 'Permissions for this service may not be enabled by your SSO Admin, or the selected region may not be supported.',
}
}
if (
e instanceof ToolkitError &&
(e.code === trustedDomainCancellation || e.cause?.name === trustedDomainCancellation)
) {
return {
id: 'trustedDomainCancellation',
text: `Must 'Open' or 'Configure Trusted Domains', unless you cancelled.`,
}
}
const invalidRequestException = 'InvalidRequestException'
if (
(e instanceof Error && e.name === invalidRequestException) ||
(e instanceof ToolkitError && e.cause?.name === invalidRequestException)
) {
return { id: 'badStartUrl', text: `Connection failed. Please verify your start URL.` }
}
// If SSO setup fails we want to be able to show the user an error in the UI, due to this we cannot
// throw an error here. So instead this will additionally show an error message that provides more
// detailed information.
handleWebviewError(e, this.id, methodName)
return { id: 'defaultFailure', text: 'Failed to setup.' }
}
}
// Add context to our telemetry by adding the methodName argument to the function stack
const result = await telemetry.function_call.run(
async () => {
return runSetup()
},
{ emit: false, functionId: { name: methodName, class: this.className } }
)
if (postMetrics) {
this.storeMetricMetadata(this.getResultForMetrics(result))
this.emitAuthMetric()
}
this.authSource = AuthSources.vscodeComponent
return result
}