File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import type { InterceptorErrorHandler } from './index.ts'
99import { generateUrl } from '@nextcloud/router'
1010import { isAxiosError } from 'axios'
1111
12- const RETRY_KEY = Symbol ( 'csrf-retry' )
12+ const RETRY_KEY = '_nextcloudCsrfTokenReloaded'
1313
1414/**
1515 * Handle CSRF token errors in Axios requests.
@@ -26,7 +26,7 @@ export function onCsrfTokenError(axios: CancelableAxiosInstance): InterceptorErr
2626 const responseURL = request ?. responseURL
2727
2828 if ( config
29- && ! config [ RETRY_KEY ]
29+ && ! ( RETRY_KEY in config )
3030 && response ?. status === 412
3131 && response ?. data ?. message === 'CSRF check failed' ) {
3232 console . warn ( `Request to ${ responseURL } failed because of a CSRF mismatch. Fetching a new token` )
@@ -35,14 +35,9 @@ export function onCsrfTokenError(axios: CancelableAxiosInstance): InterceptorErr
3535 console . debug ( `New request token ${ token } fetched` )
3636 axios . defaults . headers . requesttoken = token
3737
38- return axios ( {
39- ...config ,
40- headers : {
41- ...config . headers ,
42- requesttoken : token ,
43- } ,
44- [ RETRY_KEY ] : true ,
45- } )
38+ config . headers . requesttoken = token
39+ config [ RETRY_KEY ] = true
40+ return axios ( config )
4641 }
4742
4843 throw error
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import type { InterceptorErrorHandler } from './index.ts'
88
99import { isAxiosError } from 'axios'
1010
11- export const RETRY_DELAY_KEY = Symbol ( 'retryDelay' )
11+ const RETRY_DELAY_KEY = '_nextcloudMaintenanceModeRetryDelay'
1212
1313/**
1414 * Handles Nextcloud maintenance mode errors in Axios requests.
@@ -25,9 +25,7 @@ export function onMaintenanceModeError(axios: CancelableAxiosInstance): Intercep
2525 const responseURL = request ?. responseURL
2626 const status = response ?. status
2727 const headers = response ?. headers
28- let retryDelay = typeof config ?. [ RETRY_DELAY_KEY ] === 'number'
29- ? config ?. [ RETRY_DELAY_KEY ]
30- : 1
28+ let retryDelay = config ?. [ RETRY_DELAY_KEY ] ?? 1
3129
3230 /**
3331 * Retry requests if they failed due to maintenance mode
Original file line number Diff line number Diff line change 99declare module 'axios' {
1010 // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any -- needed as we extend the interface only.
1111 interface AxiosRequestConfig < D = any > {
12- [ key : symbol ] : unknown
12+ _nextcloudCsrfTokenReloaded ?: true
13+ _nextcloudMaintenanceModeRetryDelay ?: number
1314 }
1415}
1516
17+ declare global {
18+ var OC : {
19+ /** NC 32 and before */
20+ reload ?: ( ) => void
21+ } | undefined
22+ }
23+
1624export { }
You can’t perform that action at this time.
0 commit comments