- modify type -> interface and import path, param name
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { merge } from 'lodash'
|
||||
import type { AxiosError, AxiosInstance, AxiosRequestConfig, CancelTokenSource } from 'axios'
|
||||
import axios from 'axios'
|
||||
import { HTTP_METHODS } from '../../constants'
|
||||
import { getError, parseResponse } from './parse'
|
||||
import { HTTP_METHODS } from '~/constants'
|
||||
import { config } from '~/configs'
|
||||
import type { RequestOptions } from '~/types/models/requestOptions'
|
||||
|
||||
@@ -16,12 +16,12 @@ const axiosInstance = axios.create({
|
||||
const axiosInstanceSource = CancelToken.source()
|
||||
|
||||
export function setAxiosRequestConfig(
|
||||
api: AxiosInstance, source: CancelTokenSource, methodType: string, url: string, options?: RequestOptions,
|
||||
api: AxiosInstance, { token: cancelToken }: CancelTokenSource, method: string, url: string, options?: RequestOptions,
|
||||
) {
|
||||
const requestConfig = merge({
|
||||
url,
|
||||
cancelToken: source.token,
|
||||
method: methodType,
|
||||
cancelToken,
|
||||
method,
|
||||
}, options)
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
@@ -44,8 +44,8 @@ export function getHttpMethodsWithCancel(
|
||||
source = axiosInstanceSource,
|
||||
parse = parseResponse,
|
||||
) {
|
||||
const getApiPromise = (methodType: string, url: string, options?: RequestOptions) =>
|
||||
setAxiosRequestConfig(api, source, methodType, url, options)
|
||||
const getApiPromise = (method: string, url: string, options?: RequestOptions) =>
|
||||
setAxiosRequestConfig(api, source, method, url, options)
|
||||
.then(parse)
|
||||
.catch((error: AxiosError) => {
|
||||
getError(error)
|
||||
|
||||
Reference in New Issue
Block a user