@@ -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 ( / \/ c o m p u t e \ /s e s s i o n s \/ [ a - z A - Z 0 - 9 - ] * \ /f i l e s \/ / , "" ) ,
465474 ) ;
466475 }
467476
0 commit comments