Skip to content

Commit 9f24d79

Browse files
Scott DoverScott Dover
authored andcommitted
chore: fix session issues
Signed-off-by: Scott Dover <Scott.Dover@sas.com>
1 parent 37b6ea7 commit 9f24d79

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

client/src/components/ContentNavigator/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,10 @@ class ContentNavigator implements SubscriptionProvider {
269269
);
270270
},
271271
),
272-
commands.registerCommand(`${SAS}.collapseAllContent`, () => {
273-
commands.executeCommand(
274-
`workbench.actions.treeView.${this.treeIdentifier}.collapseAll`,
275-
);
276-
}),
272+
commands.registerCommand(
273+
`${SAS}.collapseAllContent`,
274+
this.collapseAllContent,
275+
),
277276
commands.registerCommand(
278277
`${SAS}.convertNotebookToFlow`,
279278
async (resource: ContentItem | Uri) => {
@@ -386,15 +385,24 @@ class ContentNavigator implements SubscriptionProvider {
386385
async (event: ConfigurationChangeEvent) => {
387386
if (event.affectsConfiguration("SAS.connectionProfiles")) {
388387
const endpoint = this.viyaEndpoint();
388+
this.collapseAllContent();
389389
if (endpoint) {
390390
await this.contentDataProvider.connect(endpoint);
391+
} else {
392+
await this.contentDataProvider.refresh();
391393
}
392394
}
393395
},
394396
),
395397
];
396398
}
397399

400+
private collapseAllContent() {
401+
commands.executeCommand(
402+
`workbench.actions.treeView.${this.treeIdentifier}.collapseAll`,
403+
);
404+
}
405+
398406
private async uploadResource(
399407
resource: ContentItem,
400408
openDialogOptions: Partial<OpenDialogOptions> = {},

client/src/connection/rest/RestSASServerAdapter.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,22 @@ class RestSASServerAdapter implements ContentAdapter {
5858
recycleItem?: (item: ContentItem) => Promise<{ newUri?: Uri; oldUri?: Uri }>;
5959
restoreItem?: (item: ContentItem) => Promise<boolean>;
6060

61-
public async connect(): Promise<void> {
61+
private async establishConnection() {
6262
const session = getSession();
6363
session.onSessionLogFn = appendSessionLogFn;
64-
6564
await session.setup(true);
66-
6765
this.sessionId = session?.sessionId();
66+
67+
return this.sessionId;
68+
}
69+
70+
public async connect(): Promise<void> {
71+
await this.establishConnection();
6872
// This proxies all calls to the fileSystem api to reconnect
6973
// if we ever get a 401 (unauthorized)
70-
const reconnect = async () => await this.connect();
74+
const reconnect = async () => {
75+
return await this.establishConnection();
76+
};
7177
this.fileSystemApi = new Proxy(FileSystemApi(getApiConfig()), {
7278
get: function (target, property) {
7379
if (typeof target[property] === "function") {
@@ -76,11 +82,14 @@ class RestSASServerAdapter implements ContentAdapter {
7682
try {
7783
return await target(...argList);
7884
} catch (error) {
79-
if (error.response?.status !== 401) {
80-
throw error;
81-
}
85+
// If we get any error, lets reconnect and try again. If we fail a second time,
86+
// then we can assume it's a "real" error
87+
const sessionId = await reconnect();
8288

83-
await reconnect();
89+
// If we reconnected, lets make sure we update our session id
90+
if (argList.length && argList[0].sessionId) {
91+
argList[0].sessionId = sessionId;
92+
}
8493

8594
return await target(...argList);
8695
}
@@ -461,7 +470,7 @@ class RestSASServerAdapter implements ContentAdapter {
461470

462471
private trimComputePrefix(uri: string): string {
463472
return decodeURI(
464-
uri.replace(`/compute/sessions/${this.sessionId}/files/`, ""),
473+
uri.replace(/\/compute\/sessions\/[a-zA-Z0-9-]*\/files\//, ""),
465474
);
466475
}
467476

0 commit comments

Comments
 (0)