tonhowtf/omniget · error

Twitch GQL respondeu HTTP {}

Error message

Twitch GQL respondeu HTTP {}

What it means

The Twitch GQL client in omniget-core aborts with this error when the GraphQL endpoint returns a non-success, non-retryable HTTP status (anything not 429 and not a 5xx). The post helper retries transient failures (429 rate limits and server errors) up to 5 times, but treats other 4xx responses as permanent and bails immediately via anyhow. It signals that the request itself was rejected — typically bad query syntax, authentication issues, or an unexpected client error — rather than a transient outage.

Solutions

  1. Log or print the full HTTP status and response body to identify which 4xx Twitch returned and why.
  2. Verify the GraphQL query text and variables against Twitch's current public GQL schema (IntrospectionQuery or a playground).
  3. Ensure required headers (Client-Id, Client-Integrity, OAuth token if the operation is not anonymous) are set on the request.
  4. Update persisted-query hashes / operation names if Twitch rotated them.
  5. If the status is 429 or 5xx, note this error path is not taken — rely on the existing retry loop and inspect the separate 'não respondeu depois de 5 tentativas' error instead.

Example fix

// before
if !status.is_success() {
    bail!("Twitch GQL respondeu HTTP {}", status);
}
// after
if !status.is_success() {
    let body = resp.text().await.unwrap_or_default();
    bail!("Twitch GQL respondeu HTTP {}: {}", status, body);
}
Defensive patterns

Strategy: try-catch

Try / catch

match gql.query("{ ... }").await {
    Ok(data) => handle(data),
    Err(e) if e.to_string().contains("Twitch GQL respondeu HTTP") => {
        // non-retryable 4xx: log status, check auth headers/query syntax
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling GqlClient::post (directly or via query/persisted query helpers) with a request that Twitch answers with e.g. HTTP 400 (malformed query/variables), 401/403 (missing or invalid Client-Integrity or auth headers), or 404 (endpoint/operation no longer exists).

Common situations: Twitch changes its GQL schema or persisted-query hashes; missing Client-Integrity header now required by Twitch; malformed GraphQL variables built by the caller; corporate proxy or DNS interception returning 403/404; Twitch blocking anonymous queries from certain regions/ASNs.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/c893fcdb69e93517. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/twitch/gql.rs:165

                .header("Origin", "https://www.twitch.tv")
                .header("Referer", "https://www.twitch.tv/")
                .json(body)
                .send()
                .await;
            let resp = match sent {
                Ok(r) => r,
                Err(e) => {
                    last = e.to_string();
                    continue;
                }
            };
            let status = resp.status();
            if status.as_u16() == 429 || status.is_server_error() {
                last = format!("HTTP {}", status);
                continue;
            }
            if !status.is_success() {
                bail!("Twitch GQL respondeu HTTP {}", status);
            }
            return Ok(resp.json::<Value>().await?);
        }
        bail!("Twitch GQL não respondeu depois de 5 tentativas: {}", last)
    }

    /// Query anônima em texto (as públicas aceitam sem persisted query).
    pub async fn query(&self, query: &str) -> anyhow::Result<Value> {
        let body = json!({ "query": query });
        let json = self.post(&body).await?;
        if let Some(msg) = first_error(&json) {
            bail!("Twitch GQL: {}", msg);
        }
        json.get("data")
            .cloned()
            .ok_or_else(|| anyhow!("resposta do Twitch GQL sem `data`"))
    }

View on GitHub (pinned to 8600b91f42)