@@ -206,19 +206,15 @@ export default class Client {
206
206
async send < T = any > ( path : string , reqOptions : SendOptions ) : Promise < T > {
207
207
let options = Object . assign ( { method : 'GET' } as SendOptions , reqOptions ) ;
208
208
209
- // JSON serialize the body if needed and set the correct content type
209
+ // add the json header, if not already
210
210
// (for FormData body the Content-Type header should be skipped since the boundary is autogenerated)
211
- if ( ! this . isFormData ( options . body ) ) {
212
- if ( options . body && typeof options . body !== 'string' ) {
213
- options . body = JSON . stringify ( options . body ) ;
214
- }
215
-
216
- // add the json header (if not already)
217
- if ( typeof options ?. headers ?. [ 'Content-Type' ] === 'undefined' ) {
218
- options . headers = Object . assign ( { } , options . headers , {
219
- 'Content-Type' : 'application/json' ,
220
- } ) ;
221
- }
211
+ if (
212
+ ! this . isFormData ( options . body ) &&
213
+ typeof options ?. headers ?. [ 'Content-Type' ] === 'undefined'
214
+ ) {
215
+ options . headers = Object . assign ( { } , options . headers , {
216
+ 'Content-Type' : 'application/json' ,
217
+ } ) ;
222
218
}
223
219
224
220
// add Accept-Language header (if not already)
@@ -279,6 +275,15 @@ export default class Client {
279
275
}
280
276
}
281
277
278
+ // ensures that the json body is serialized
279
+ if (
280
+ options ?. headers ?. [ 'Content-Type' ] == 'application/json' &&
281
+ options . body &&
282
+ typeof options . body !== 'string'
283
+ ) {
284
+ options . body = JSON . stringify ( options . body ) ;
285
+ }
286
+
282
287
// send the request
283
288
return fetch ( url , options )
284
289
. then ( async ( response ) => {
0 commit comments