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:
@@ -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. ')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user