@@ -14,15 +14,21 @@ export interface ResponseWrapper<T> {
14
14
} ;
15
15
}
16
16
17
- function requestArgsToJson ( args : RequestArgs ) : JsonObject {
18
- // Convert the entire args object to a JSON-serializable format
19
- const argsWithData = args as RequestArgs & { data ?: Blob | ArrayBuffer } ;
20
- return JSON . parse (
21
- JSON . stringify ( {
22
- ...argsWithData ,
23
- data : argsWithData . data ? "[Blob or ArrayBuffer]" : null ,
24
- } )
25
- ) as JsonObject ;
17
+ function bodyToJson ( body ?: BodyInit | null ) : JsonObject {
18
+ let data = null ;
19
+ if ( body instanceof Blob || body instanceof ArrayBuffer ) {
20
+ data = "[Blob or ArrayBuffer]" ;
21
+ } else if ( typeof body === "string" ) {
22
+ try {
23
+ data = JSON . parse ( body ) ;
24
+ } catch {
25
+ data = body ;
26
+ }
27
+ }
28
+ if ( data . accessToken ) {
29
+ data . accessToken = "[REDACTED]" ;
30
+ }
31
+ return data as JsonObject ;
26
32
}
27
33
28
34
/**
@@ -60,7 +66,7 @@ export async function innerRequest<T>(
60
66
url,
61
67
method : info . method ?? "GET" ,
62
68
headers : info . headers as Record < string , string > ,
63
- body : requestArgsToJson ( args ) ,
69
+ body : bodyToJson ( info . body ) ,
64
70
} ,
65
71
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : output }
66
72
) ;
@@ -72,7 +78,7 @@ export async function innerRequest<T>(
72
78
url,
73
79
method : info . method ?? "GET" ,
74
80
headers : info . headers as Record < string , string > ,
75
- body : requestArgsToJson ( args ) ,
81
+ body : bodyToJson ( info . body ) ,
76
82
} ,
77
83
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : output }
78
84
) ;
@@ -83,7 +89,7 @@ export async function innerRequest<T>(
83
89
url,
84
90
method : info . method ?? "GET" ,
85
91
headers : info . headers as Record < string , string > ,
86
- body : requestArgsToJson ( args ) ,
92
+ body : bodyToJson ( info . body ) ,
87
93
} ,
88
94
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : output }
89
95
) ;
@@ -96,7 +102,7 @@ export async function innerRequest<T>(
96
102
url,
97
103
method : info . method ?? "GET" ,
98
104
headers : info . headers as Record < string , string > ,
99
- body : requestArgsToJson ( args ) ,
105
+ body : bodyToJson ( info . body ) ,
100
106
} ,
101
107
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : message ?? "" }
102
108
) ;
@@ -142,7 +148,7 @@ export async function* innerStreamingRequest<T>(
142
148
url,
143
149
method : info . method ?? "GET" ,
144
150
headers : info . headers as Record < string , string > ,
145
- body : requestArgsToJson ( args ) ,
151
+ body : bodyToJson ( info . body ) ,
146
152
} ,
147
153
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : output }
148
154
) ;
@@ -154,7 +160,7 @@ export async function* innerStreamingRequest<T>(
154
160
url,
155
161
method : info . method ?? "GET" ,
156
162
headers : info . headers as Record < string , string > ,
157
- body : requestArgsToJson ( args ) ,
163
+ body : bodyToJson ( info . body ) ,
158
164
} ,
159
165
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : output }
160
166
) ;
@@ -167,7 +173,7 @@ export async function* innerStreamingRequest<T>(
167
173
url,
168
174
method : info . method ?? "GET" ,
169
175
headers : info . headers as Record < string , string > ,
170
- body : requestArgsToJson ( args ) ,
176
+ body : bodyToJson ( info . body ) ,
171
177
} ,
172
178
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : output }
173
179
) ;
@@ -180,7 +186,7 @@ export async function* innerStreamingRequest<T>(
180
186
url,
181
187
method : info . method ?? "GET" ,
182
188
headers : info . headers as Record < string , string > ,
183
- body : requestArgsToJson ( args ) ,
189
+ body : bodyToJson ( info . body ) ,
184
190
} ,
185
191
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : output }
186
192
) ;
@@ -193,7 +199,7 @@ export async function* innerStreamingRequest<T>(
193
199
url,
194
200
method : info . method ?? "GET" ,
195
201
headers : info . headers as Record < string , string > ,
196
- body : requestArgsToJson ( args ) ,
202
+ body : bodyToJson ( info . body ) ,
197
203
} ,
198
204
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : "" }
199
205
) ;
@@ -206,7 +212,7 @@ export async function* innerStreamingRequest<T>(
206
212
url,
207
213
method : info . method ?? "GET" ,
208
214
headers : info . headers as Record < string , string > ,
209
- body : requestArgsToJson ( args ) ,
215
+ body : bodyToJson ( info . body ) ,
210
216
} ,
211
217
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : "" }
212
218
) ;
@@ -261,7 +267,7 @@ export async function* innerStreamingRequest<T>(
261
267
url,
262
268
method : info . method ?? "GET" ,
263
269
headers : info . headers as Record < string , string > ,
264
- body : requestArgsToJson ( args ) ,
270
+ body : bodyToJson ( info . body ) ,
265
271
} ,
266
272
{ requestId : response . headers . get ( "x-request-id" ) ?? "" , status : response . status , body : data }
267
273
) ;
0 commit comments