Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
StarksJohn committed Dec 16, 2023
1 parent 1f4c6f4 commit 1a69d19
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-ignore
import axios, {AxiosInstance, AxiosRequestConfig, AxiosResponse} from 'axios'
// @ts-ignore
import qs from 'qs'
// @ts-ignore
import cleanDeep from 'clean-deep'

const defaultheaders = {
Expand All @@ -21,7 +23,6 @@ interface axiosToolsResponse {

/**
* Request interceptor
* @param config: Pass as a parameter of api.get() | api.post() method
*/
const handleRequestConfig = (config: AxiosRequestConfig) => {
console.log('axios-tools handleRequestConfig config=', config)
Expand All @@ -33,7 +34,7 @@ const handleRequestConfig = (config: AxiosRequestConfig) => {
})
// const Config=config
if (Config.method === 'get') {
Config.paramsSerializer = params => {
Config.paramsSerializer = (params: any) => {
console.log('axios-tools paramsSerializer params=', params)
// A querystring parsing and stringifying library with some added security.
const qsStr = qs.stringify(params, {
Expand Down Expand Up @@ -139,10 +140,11 @@ class Api {
*/
withCredentials: true,
headers: defaultheaders,
// @ts-ignore
...baseConfig
})
// Request interceptor
this.instance.interceptors.request.use(handleRequestConfig, error => {
this.instance.interceptors.request.use(handleRequestConfig, (error: any) => {
// Do something with request error
console.log('axios-tools interceptors.request error=', error)
return Promise.reject(error)
Expand Down

0 comments on commit 1a69d19

Please sign in to comment.