@@ -58,16 +58,22 @@ class RestSASServerAdapter implements ContentAdapter {
58
58
recycleItem ?: ( item : ContentItem ) => Promise < { newUri ?: Uri ; oldUri ?: Uri } > ;
59
59
restoreItem ?: ( item : ContentItem ) => Promise < boolean > ;
60
60
61
- public async connect ( ) : Promise < void > {
61
+ private async establishConnection ( ) {
62
62
const session = getSession ( ) ;
63
63
session . onSessionLogFn = appendSessionLogFn ;
64
-
65
64
await session . setup ( true ) ;
66
-
67
65
this . sessionId = session ?. sessionId ( ) ;
66
+
67
+ return this . sessionId ;
68
+ }
69
+
70
+ public async connect ( ) : Promise < void > {
71
+ await this . establishConnection ( ) ;
68
72
// This proxies all calls to the fileSystem api to reconnect
69
73
// if we ever get a 401 (unauthorized)
70
- const reconnect = async ( ) => await this . connect ( ) ;
74
+ const reconnect = async ( ) => {
75
+ return await this . establishConnection ( ) ;
76
+ } ;
71
77
this . fileSystemApi = new Proxy ( FileSystemApi ( getApiConfig ( ) ) , {
72
78
get : function ( target , property ) {
73
79
if ( typeof target [ property ] === "function" ) {
@@ -76,11 +82,14 @@ class RestSASServerAdapter implements ContentAdapter {
76
82
try {
77
83
return await target ( ...argList ) ;
78
84
} 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 ( ) ;
82
88
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
+ }
84
93
85
94
return await target ( ...argList ) ;
86
95
}
@@ -461,7 +470,7 @@ class RestSASServerAdapter implements ContentAdapter {
461
470
462
471
private trimComputePrefix ( uri : string ) : string {
463
472
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 \/ / , "" ) ,
465
474
) ;
466
475
}
467
476
0 commit comments