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:
@@ -35,11 +35,11 @@ export const handleBadResponses = (
|
||||
}
|
||||
if (response.status >= 400) {
|
||||
const data = (response.data as Record<string, unknown>) || {};
|
||||
const detail = (data.detail ||
|
||||
data.error ||
|
||||
data.message ||
|
||||
response.content ||
|
||||
'unknown error') as string;
|
||||
const raw =
|
||||
data.detail || data.error || data.message || response.content || 'unknown error';
|
||||
// DRF sometimes returns detail as an object/array; stringify so the
|
||||
// thrown message never renders as "[object Object]".
|
||||
const detail = typeof raw === 'string' ? raw : JSON.stringify(raw);
|
||||
throw new z.errors.Error(
|
||||
`Mem0 API request failed (HTTP ${response.status}): ${detail}`,
|
||||
'Mem0ApiError',
|
||||
|
||||
Reference in New Issue
Block a user