@parallelworks/client 7.41.0 → 7.42.0

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -248,18 +248,32 @@ export class Client {
248
248
  // (e.g. SWR hooks) can distinguish 404s from other errors.
249
249
  // openapi-fetch parses the body after middleware, so we replace the
250
250
  // response with one whose body includes the status field.
251
+ // Also guarantee `message` is populated — upstream infrastructure (WAFs,
252
+ // proxies) can return non-2xx with an empty body, which would otherwise
253
+ // short-circuit openapi-fetch (it returns `error: undefined` when
254
+ // Content-Length is 0) and leave consumers with no error to react to.
251
255
  const statusMiddleware = {
252
256
  async onResponse({ response }) {
253
257
  if (!response.ok) {
254
258
  const body = await response.json().catch(() => ({}));
255
- if (body && typeof body === 'object') {
256
- ;
257
- body.status = response.status;
259
+ const record = body && typeof body === 'object'
260
+ ? body
261
+ : {};
262
+ record.status = response.status;
263
+ if (typeof record.message !== 'string' || !record.message) {
264
+ record.message =
265
+ response.statusText ||
266
+ `Request failed with status ${response.status}`;
258
267
  }
259
- return new Response(JSON.stringify(body), {
268
+ // Strip Content-Length from the original headers — we're replacing
269
+ // the body, and a stale `Content-Length: 0` from an empty upstream
270
+ // response causes openapi-fetch to skip body parsing entirely.
271
+ const headers = new Headers(response.headers);
272
+ headers.delete('content-length');
273
+ return new Response(JSON.stringify(record), {
260
274
  status: response.status,
261
275
  statusText: response.statusText,
262
- headers: response.headers,
276
+ headers,
263
277
  });
264
278
  }
265
279
  return response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parallelworks/client",
3
- "version": "7.41.0",
3
+ "version": "7.42.0",
4
4
  "description": "Official TypeScript client for Parallel Works ACTIVATE API",
5
5
  "type": "module",
6
6
  "exports": {