@ace-fetch/uni-app
Version:
uni-app adapter for @ace-fetch/core.
41 lines (40 loc) • 1.56 kB
TypeScript
import type { RequestConfig } from '@ace-fetch/core';
export interface Interceptor<V = any, T = V> {
fulfilled?: (value: V) => T | Promise<T>;
rejected?: (error: any) => any;
synchronous: boolean;
runWhen: ((config: RequestConfig) => boolean) | null;
}
export interface InterceptorOptions {
synchronous?: boolean;
runWhen?: (config: RequestConfig) => boolean;
}
export declare class InterceptorManager<V = any> {
handlers: Array<Interceptor | null>;
/**
* Add a new interceptor to the stack
* @param {Function} fulfilled The function to handle `then` for a `Promise`
* @param {Function} rejected The function to handle `reject` for a `Promise`
* @return {Number} An ID used to remove interceptor later
*/
use<T = V>(fulfilled?: Interceptor<V, T>['fulfilled'], rejected?: Interceptor<V, T>['rejected'], options?: InterceptorOptions): number;
/**
* Remove an interceptor from the stack
* @param {Number} id The ID that was returned by `use`
* @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
*/
eject(id: number): void;
/**
* Clear all interceptors from the stack
* @returns {void}
*/
clear(): void;
/**
* Iterate over all the registered interceptors
* This method is particularly useful for skipping over any
* interceptors that may have become `null` calling `eject`.
* @param {Function} fn The function to call for each interceptor
* @returns {void}
*/
forEach(fn: Function): void;
}