fix(integrations): address code-review findings

n8n: throw on FAILED memory events (was silently returned), poll on any
non-terminal status (PENDING or RUNNING), use top_k (not limit) for
search, coerce search/getAll responses to arrays, guard invalid-JSON
metadata, reject empty updates, mark user_id required; lint clean.

Zapier: coerce boolean fields (String(x) !== 'false') + boolean defaults
so "Wait"/"Infer = No" are honored, throw on HTTP >= 400 (was silent
empty/fake-success), throw on FAILED events, use top_k, numeric coercion
with clamping, mark user_id required.
This commit is contained in:
Himanshu-Sangshetti
2026-07-20 11:55:29 +05:30
parent 9882eea7b8
commit e66e97b725
8 changed files with 136 additions and 54 deletions
+12 -1
View File
@@ -14,7 +14,9 @@ const includeApiKey = (request, z, bundle) => {
return request;
};
// Surface auth failures as Zapier auth errors so users are prompted to reconnect.
// Surface HTTP failures as errors. z.request does NOT throw on non-2xx by
// default, so without this a 4xx/5xx would flow downstream as a fake success
// (empty search results / error body returned as a created memory).
const handleBadResponses = (response, z, _bundle) => {
if (response.status === 401 || response.status === 403) {
throw new z.errors.Error(
@@ -23,6 +25,15 @@ const handleBadResponses = (response, z, _bundle) => {
response.status,
);
}
if (response.status >= 400) {
const data = response.data || {};
const detail = data.detail || data.error || data.message || response.content || 'unknown error';
throw new z.errors.Error(
`Mem0 API request failed (HTTP ${response.status}): ${detail}`,
'Mem0ApiError',
response.status,
);
}
return response;
};