1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-04-19 04:03:13 +00:00

fix: handle session inactivity expiry

This commit is contained in:
mulahasanovic
2026-04-15 08:57:34 +02:00
parent b92487819a
commit fe5f0e87b7
4 changed files with 73 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ export class RequestClient implements HttpClient {
protected csrfToken: CsrfToken = { headerName: '', value: '' }
protected fileUploadCsrfToken: CsrfToken | undefined
protected httpClient!: AxiosInstance
private isRecoveringFromNetworkError = false
constructor(
protected baseUrl: string,
@@ -77,6 +78,16 @@ export class RequestClient implements HttpClient {
localStorage.setItem('refreshToken', '')
}
public resetInMemoryAuthState() {
this.clearCsrfTokens()
if (typeof localStorage !== 'undefined') {
this.clearLocalStorageTokens()
}
if (typeof document !== 'undefined') {
document.cookie = 'XSRF-TOKEN=; Max-Age=0; Path=/;'
}
}
public getBaseUrl() {
return this.httpClient.defaults.baseURL || ''
}
@@ -687,6 +698,24 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
throw new CertificateError(e.message)
}
if (
e.isAxiosError &&
!response &&
e.code === 'ERR_NETWORK' &&
!this.isRecoveringFromNetworkError
) {
// Opaque ERR_NETWORK usually means the server rejected stale credentials.
// Wipe in-memory auth state so the retry either succeeds
// or surfaces a clean LoginRequiredError.
this.resetInMemoryAuthState()
this.isRecoveringFromNetworkError = true
try {
return await callback()
} finally {
this.isRecoveringFromNetworkError = false
}
}
if (e.message) throw e
else throw prefixMessage(e, 'Error while handling error. ')
}