export interface AxiosInterceptorManager {
use(resolved: ResolvedFn, rejected?: RejectedFn): number
eject(id: number): void
}
export default class InterceptorManager {
private interceptors: Array<Interceptor | null>
constructor() {
this.interceptors = []
}
use(resolved: ResolvedFn, rejected?: RejectedFn): number {
this.interceptors.push({
resolved,
rejected
})
return this.interceptors.length - 1
}
forEach(fn: (interceptor: Interceptor) => void): void {
this.interceptors.forEach(interceptor => {
if (interceptor !== null) {
fn(interceptor)
}
})
}
eject(id: number): void {
if (this.interceptors[id]) {
this.interceptors[id] = null
}
}
}