async function callZenstepAPI(url, options) {
const response = await fetch(url, options);
if (!response.ok) {
const body = await response
.json()
.catch(() => ({ error: "Unknown error" }));
switch (response.status) {
case 400:
console.error("[Zenstep] Validation error:", body.details);
break;
case 401:
console.error(
"[Zenstep] Authentication failed — check your snippet key",
);
break;
case 429:
console.warn(
`[Zenstep] Rate limited — retry after ${body.retryAfter}s`,
);
break;
case 500:
console.error("[Zenstep] Server error — check status.getzenstep.com");
break;
default:
console.error("[Zenstep] API error:", body.error);
}
throw new Error(body.error);
}
return response.json();
}