@@ -121,26 +121,39 @@ class RequestHelper {
121
121
}
122
122
123
123
static async request ( type , service , endpoint , options = { } , form = false , stream = false ) {
124
- const requestOptions = defaultRequest ( service , endpoint , {
125
- headers : service . headers ,
126
- } ) ;
127
-
128
124
try {
129
125
switch ( type ) {
130
126
case 'get' :
131
127
if ( stream ) return await getStream ( service , endpoint , options ) ;
132
128
return await getPaginated ( service , endpoint , options ) ;
129
+
133
130
case 'post' : {
134
- const body = form ? 'formData' : 'body' ;
135
- requestOptions [ body ] = options ;
131
+ const requestOptions = defaultRequest ( service , endpoint , {
132
+ headers : service . headers ,
133
+ [ form ? 'formData' : 'body' ] : options ,
134
+ } ) ;
135
+
136
136
return await service . requester . post ( requestOptions ) ;
137
137
}
138
- case 'put' :
139
- requestOptions . body = options ;
138
+
139
+ case 'put' : {
140
+ const requestOptions = defaultRequest ( service , endpoint , {
141
+ headers : service . headers ,
142
+ body : options ,
143
+ } ) ;
144
+
140
145
return await service . requester . put ( requestOptions ) ;
141
- case 'delete' :
142
- requestOptions . qs = options ;
146
+ }
147
+
148
+ case 'delete' : {
149
+ const requestOptions = defaultRequest ( service , endpoint , {
150
+ headers : service . headers ,
151
+ qs : options ,
152
+ } ) ;
153
+
143
154
return await service . requester . delete ( requestOptions ) ;
155
+ }
156
+
144
157
default :
145
158
throw new Error ( `Unknown request type ${ type } ` ) ;
146
159
}
0 commit comments