Skip to content

Commit

Permalink
fix: remove custom params serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolink committed Jul 18, 2023
1 parent 9f31d20 commit d9a4f4a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
"fast-copy": "^2.1.7",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"p-throttle": "^4.1.1",
"qs": "^6.11.2"
"p-throttle": "^4.1.1"
},
"devDependencies": {
"@babel/cli": "^7.12.8",
Expand All @@ -66,7 +65,6 @@
"@types/jest": "^29.2.2",
"@types/lodash.isplainobject": "^4.0.6",
"@types/lodash.isstring": "^4.0.6",
"@types/qs": "^6.9.5",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"axios": "^1.4.0",
Expand Down
14 changes: 4 additions & 10 deletions src/create-http-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AxiosRequestHeaders } from 'axios'
import type { AxiosStatic } from 'axios'
import copy from 'fast-copy'
import qs from 'qs'
import asyncToken from './async-token'

import rateLimitRetry from './rate-limit'
Expand All @@ -17,7 +16,7 @@ const HOST_REGEX = /^(?!\w+:\/\/)([^\s:]+\.?[^\s:]+)(?::(\d+))?(?!:)$/
* @private
* @param {AxiosStatic} axios - Axios library
* @param {CreateHttpClientParams} options - Initialization parameters for the HTTP client
* @return {ContentfulAxiosInstance} Initialized axios instance
* @return {AxiosInstance} Initialized axios instance
*/
export default function createHttpClient(
axios: AxiosStatic,
Expand All @@ -42,7 +41,6 @@ export default function createHttpClient(
httpsAgent: false as const,
timeout: 30000,
throttle: 0,
proxy: false as const,
basePath: '',
adapter: undefined,
maxContentLength: 1073741824, // 1GB
Expand Down Expand Up @@ -91,11 +89,6 @@ export default function createHttpClient(
headers: config.headers,
httpAgent: config.httpAgent,
httpsAgent: config.httpsAgent,
paramsSerializer: {
serialize: (params) => {
return qs.stringify(params, { arrayFormat: 'repeat' })
},
},
proxy: config.proxy,
timeout: config.timeout,
adapter: config.adapter,
Expand All @@ -107,6 +100,7 @@ export default function createHttpClient(
requestLogger: config.requestLogger,
retryOnError: config.retryOnError,
}

const instance = axios.create(axiosOptions) as AxiosInstance
instance.httpClientParams = options

Expand All @@ -117,8 +111,8 @@ export default function createHttpClient(
* and the version of the library comes from different places depending
* on whether it's a browser build or a node.js build.
* @private
* @param {CreateHttpClientParams} httpClientParams - Initialization parameters for the HTTP client
* @return {ContentfulAxiosInstance} Initialized axios instance
* @param {CreateHttpClientParams} newParams - Initialization parameters for the HTTP client
* @return {AxiosInstance} Initialized axios instance
*/
instance.cloneWithNewParams = function (
newParams: Partial<CreateHttpClientParams>
Expand Down
3 changes: 1 addition & 2 deletions src/error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isPlainObject from 'lodash.isplainobject'
import type { AxiosError } from 'axios'
import type { ContentfulErrorData } from './types'

/**
Expand All @@ -10,7 +9,7 @@ import type { ContentfulErrorData } from './types'
* and the expected error codes.
* @private
*/
export default function errorHandler(errorResponse: AxiosError<ContentfulErrorData>): never {
export default function errorHandler(errorResponse: any): never {
const { config, response } = errorResponse
let errorName

Expand Down

0 comments on commit d9a4f4a

Please sign in to comment.