fix(zapier): harden null-body handling and error messages

From an independent review pass:
- Guard search / get / add against a null or empty 2xx body (previously an
  uncaught TypeError on .results / .status); return [] or an empty object.
- Stringify non-string API error detail so a thrown message never renders as
  "[object Object]".
- Correct the Add sample to the default no-wait shape {event_id, status}.
- Add a regression unit test for the null-body path.

Verified: build + zapier validate + 16 tests (13 unit, 3 live E2E), plus a
live check of the v3-add to /v1/event poll cross-version path.
This commit is contained in:
Himanshu-Sangshetti
2026-07-23 11:49:25 +05:30
parent 9b1e2ef604
commit 1bd9910382
5 changed files with 28 additions and 12 deletions
@@ -16,9 +16,9 @@ const perform = async (z: ZObject, bundle: Bundle): Promise<Memory[]> => {
method: 'POST',
body,
});
// Searches must return an array.
const data = response.data as Memory[] | { results?: Memory[] };
return Array.isArray(data) ? data : data.results || [];
// Searches must return an array; guard against a null/empty body.
const data = response.data as Memory[] | { results?: Memory[] } | null;
return Array.isArray(data) ? data : data?.results ?? [];
};
export default {