@@ -41,13 +41,13 @@ export const convertAxiosToApiGw = (config: AxiosRequestConfig, operation: Opera
41
41
}
42
42
43
43
// extract query params -> convert each value to ta string
44
- const queryParams = Object . entries ( config . params ?? { } ) . reduce < APIGatewayProxyEventQueryStringParameters > ( ( queryParams , [ key , val ] ) => {
44
+ const queryParams = Object . entries ( config . params ?? { } ) . filter ( entryValueExists ) . reduce < APIGatewayProxyEventQueryStringParameters > ( ( queryParams , [ key , val ] ) => {
45
45
queryParams [ key ] = val ?. toString ( )
46
46
return queryParams
47
47
} , { } )
48
48
49
49
const queryString : string [ ] = [ ]
50
- Object . entries ( config . params ?? { } ) . forEach ( ( [ key , val ] ) => {
50
+ Object . entries ( config . params ?? { } ) . filter ( entryValueExists ) . forEach ( ( [ key , val ] ) => {
51
51
if ( val && Array . isArray ( val ) ) {
52
52
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
53
53
queryString . push ( ...val . map ( ( entry ) => `${ key } =${ entry . toString ( ) } ` ) )
@@ -56,11 +56,8 @@ export const convertAxiosToApiGw = (config: AxiosRequestConfig, operation: Opera
56
56
}
57
57
} )
58
58
59
- const urlSearchParams = new URLSearchParams ( )
60
- Object . entries ( config . params ?? { } ) . forEach ( ( [ key , val ] ) => urlSearchParams . append ( key , val . toString ( ) ) )
61
-
62
59
const headers : Record < string , string > = { }
63
- for ( const [ key , val ] of Object . entries ( config . headers ?? { } ) . filter ( ( [ _key , val ] ) => val !== null && val !== undefined ) ) {
60
+ for ( const [ key , val ] of Object . entries ( config . headers ?? { } ) . filter ( entryValueExists ) ) {
64
61
headers [ key ] = val . toString ( )
65
62
}
66
63
@@ -124,6 +121,8 @@ export const convertApiGwToAxios = (resp: APIGatewayProxyStructuredResultV2, axi
124
121
return axiosResp
125
122
}
126
123
124
+ const entryValueExists = ( entry : [ string , unknown ] ) : boolean => entry [ 1 ] !== null && entry [ 1 ] !== undefined
125
+
127
126
class AxiosError extends Error {
128
127
public readonly code : string
129
128
public readonly config : AxiosRequestConfig
0 commit comments