@hey-api/openapi-ts 0.90.2 → 0.90.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -180,10 +180,16 @@ export const createClient = (config: Config = {}): Client => {
180
180
  case 'arrayBuffer':
181
181
  case 'blob':
182
182
  case 'formData':
183
- case 'json':
184
183
  case 'text':
185
184
  data = await response[parseAs]();
186
185
  break;
186
+ case 'json': {
187
+ // Some servers return 200 with no Content-Length and empty body.
188
+ // response.json() would throw; read as text and parse if non-empty.
189
+ const text = await response.text();
190
+ data = text ? JSON.parse(text) : {};
191
+ break;
192
+ }
187
193
  case 'stream':
188
194
  return opts.responseStyle === 'data'
189
195
  ? response.body
@@ -249,10 +249,16 @@ export const createClient = (config: Config = {}): Client => {
249
249
  case 'arrayBuffer':
250
250
  case 'blob':
251
251
  case 'formData':
252
- case 'json':
253
252
  case 'text':
254
253
  data = await response[parseAs]();
255
254
  break;
255
+ case 'json': {
256
+ // Some servers return 200 with no Content-Length and empty body.
257
+ // response.json() would throw; read as text and parse if non-empty.
258
+ const text = await response.text();
259
+ data = text ? JSON.parse(text) : {};
260
+ break;
261
+ }
256
262
  case 'stream':
257
263
  return opts.responseStyle === 'data'
258
264
  ? response.body
@@ -142,10 +142,16 @@ export const createClient = (config: Config = {}): Client => {
142
142
  case 'arrayBuffer':
143
143
  case 'blob':
144
144
  case 'formData':
145
- case 'json':
146
145
  case 'text':
147
146
  data = await response[parseAs]();
148
147
  break;
148
+ case 'json': {
149
+ // Some servers return 200 with no Content-Length and empty body.
150
+ // response.json() would throw; read as text and parse if non-empty.
151
+ const text = await response.text();
152
+ data = text ? JSON.parse(text) : {};
153
+ break;
154
+ }
149
155
  case 'stream':
150
156
  return {
151
157
  data: response.body,