From 9f24d791ed36581e1c812dd8c4186d2504e9a420 Mon Sep 17 00:00:00 2001 From: Scott Dover Date: Fri, 11 Oct 2024 15:03:11 -0400 Subject: [PATCH] chore: fix session issues Signed-off-by: Scott Dover --- .../src/components/ContentNavigator/index.ts | 18 +++++++++---- .../connection/rest/RestSASServerAdapter.ts | 27 ++++++++++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/client/src/components/ContentNavigator/index.ts b/client/src/components/ContentNavigator/index.ts index 7684924b3..8b5ea59ad 100644 --- a/client/src/components/ContentNavigator/index.ts +++ b/client/src/components/ContentNavigator/index.ts @@ -269,11 +269,10 @@ class ContentNavigator implements SubscriptionProvider { ); }, ), - commands.registerCommand(`${SAS}.collapseAllContent`, () => { - commands.executeCommand( - `workbench.actions.treeView.${this.treeIdentifier}.collapseAll`, - ); - }), + commands.registerCommand( + `${SAS}.collapseAllContent`, + this.collapseAllContent, + ), commands.registerCommand( `${SAS}.convertNotebookToFlow`, async (resource: ContentItem | Uri) => { @@ -386,8 +385,11 @@ class ContentNavigator implements SubscriptionProvider { async (event: ConfigurationChangeEvent) => { if (event.affectsConfiguration("SAS.connectionProfiles")) { const endpoint = this.viyaEndpoint(); + this.collapseAllContent(); if (endpoint) { await this.contentDataProvider.connect(endpoint); + } else { + await this.contentDataProvider.refresh(); } } }, @@ -395,6 +397,12 @@ class ContentNavigator implements SubscriptionProvider { ]; } + private collapseAllContent() { + commands.executeCommand( + `workbench.actions.treeView.${this.treeIdentifier}.collapseAll`, + ); + } + private async uploadResource( resource: ContentItem, openDialogOptions: Partial = {}, diff --git a/client/src/connection/rest/RestSASServerAdapter.ts b/client/src/connection/rest/RestSASServerAdapter.ts index 101cbd16e..b42f50254 100644 --- a/client/src/connection/rest/RestSASServerAdapter.ts +++ b/client/src/connection/rest/RestSASServerAdapter.ts @@ -58,16 +58,22 @@ class RestSASServerAdapter implements ContentAdapter { recycleItem?: (item: ContentItem) => Promise<{ newUri?: Uri; oldUri?: Uri }>; restoreItem?: (item: ContentItem) => Promise; - public async connect(): Promise { + private async establishConnection() { const session = getSession(); session.onSessionLogFn = appendSessionLogFn; - await session.setup(true); - this.sessionId = session?.sessionId(); + + return this.sessionId; + } + + public async connect(): Promise { + await this.establishConnection(); // This proxies all calls to the fileSystem api to reconnect // if we ever get a 401 (unauthorized) - const reconnect = async () => await this.connect(); + const reconnect = async () => { + return await this.establishConnection(); + }; this.fileSystemApi = new Proxy(FileSystemApi(getApiConfig()), { get: function (target, property) { if (typeof target[property] === "function") { @@ -76,11 +82,14 @@ class RestSASServerAdapter implements ContentAdapter { try { return await target(...argList); } catch (error) { - if (error.response?.status !== 401) { - throw error; - } + // If we get any error, lets reconnect and try again. If we fail a second time, + // then we can assume it's a "real" error + const sessionId = await reconnect(); - await reconnect(); + // If we reconnected, lets make sure we update our session id + if (argList.length && argList[0].sessionId) { + argList[0].sessionId = sessionId; + } return await target(...argList); } @@ -461,7 +470,7 @@ class RestSASServerAdapter implements ContentAdapter { private trimComputePrefix(uri: string): string { return decodeURI( - uri.replace(`/compute/sessions/${this.sessionId}/files/`, ""), + uri.replace(/\/compute\/sessions\/[a-zA-Z0-9-]*\/files\//, ""), ); }