> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xquik.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Zapier Twitter automation error handling helper

> Normalize Xquik API auth, credit, limit, and input errors in one Zapier helper. Every X (Twitter) automation action then reports the same fix for each error.

> For the complete documentation index, see [llms.txt](https://docs.xquik.com/llms.txt).

This guide belongs to the [Zapier Twitter integration](https://docs.xquik.com/guides/zapier.md) build.

## Shared error handling

Normalize Xquik responses in one helper. Every action then reports the same remediation.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/bash.json","/languages/csharp.json","/languages/go.json","/languages/java.json","/languages/javascript.json","/languages/kotlin.json","/languages/php.json","/languages/python.json","/languages/ruby.json","/languages/typescript.json"]}}
function throwForXquikError(z, response) {
  if (response.status < 400) {
    return;
  }

  const detail = response.data?.message || response.data?.error;

  if (response.status === 400) {
    throw new z.errors.Error(
      detail || "Invalid request. Fix the input fields.",
      "XquikInvalidRequest",
      400,
    );
  }

  if (response.status === 401) {
    throw new z.errors.RefreshAuthError("Authentication failed. Check the Xquik API key.");
  }

  if (response.status === 402) {
    throw new z.errors.Error(
      "Subscription or credits required. Update billing in Xquik.",
      "XquikBillingRequired",
      402,
    );
  }

  if (response.status === 404) {
    throw new z.errors.Error(
      detail || "Resource not found. Check the supplied ID.",
      "XquikResourceMissing",
      404,
    );
  }

  if (response.status === 424) {
    throw new z.errors.Error(
      detail || "X dependency failed. Retry only when the workflow is safe.",
      "XquikDependencyFailure",
      424,
    );
  }

  if (response.status === 429) {
    const retryAfter = Number.parseInt(
      response.getHeader?.("retry-after") || response.headers?.["retry-after"] || "",
      10,
    );

    if (Number.isInteger(retryAfter) && retryAfter > 0) {
      throw new z.errors.ThrottledError("Rate limited. Zapier scheduled a retry.", retryAfter);
    }

    throw new z.errors.Error(
      "Rate limited. Retry after the cooldown period.",
      "XquikRateLimit",
      429,
    );
  }

  if (response.status === 502) {
    throw new z.errors.Error(
      detail || "X retrieval failed. Retry with a bounded attempt count.",
      "XquikRetrievalFailure",
      502,
    );
  }

  throw new z.errors.Error(
    detail || "Xquik request failed. Inspect the safe status.",
    "XquikRequestError",
    response.status,
  );
}

async function xquikRequest(z, options) {
  const response = await z.request({
    ...options,
    skipThrowForStatus: true,
    throwForThrottlingEarly: false,
  });

  throwForXquikError(z, response);
  return response;
}
```

Call `xquikRequest(z, options)` before reading response data. Use each route's
response widget as the canonical status list.

## Next steps

* [Zapier Twitter integration](https://docs.xquik.com/guides/zapier.md)
* [Zapier result handoff](https://docs.xquik.com/guides/zapier-result-handoff.md)
* [Monitor event REST hook](https://docs.xquik.com/guides/zapier-monitor-rest-hook.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.