| 8 | |
| 9 | export default class XFetch { |
| 10 | constructor (options, MPX) { |
| 11 | this.CancelToken = CancelToken |
| 12 | this.cacheRequestData = {} |
| 13 | // this.requestAdapter = (config) => requestAdapter(config, MPX) |
| 14 | // 当存在 useQueue 配置时,才使用 this.queue 变量 |
| 15 | if (options && options.useQueue && typeof options.useQueue === 'object') { |
| 16 | this.queue = new RequestQueue(extend({ |
| 17 | adapter: (config) => requestAdapter(config, MPX) |
| 18 | }, options.useQueue)) |
| 19 | } else { |
| 20 | this.requestAdapter = (config) => requestAdapter(config, MPX) |
| 21 | } |
| 22 | if (options && options.proxy) this.setProxy(options.proxy) |
| 23 | this.onValidatorError = options?.onValidatorError || (error => { |
| 24 | console.error(error) |
| 25 | }) |
| 26 | this.interceptors = { |
| 27 | request: new InterceptorManager(), |
| 28 | response: new InterceptorManager() |
| 29 | } |
| 30 | this.useBigInt = (options && options.useBigInt) || false |
| 31 | } |
| 32 | |
| 33 | static normalizeConfig (config) { |
| 34 | if (!config.url) { |