SubtitleEdit/subtitleedit · error · Exception
An error occurred calling GT translate - status code: {resul
Error message
An error occurred calling GT translate - status code: {result.StatusCode} What it means
Thrown by GoogleTranslateV2 as the catch-all for any non-success status that is not 400 or 403 (those are handled explicitly above). The status code is included. This covers 429 (rate limit), 5xx (Google server errors), and other unexpected responses.
Source
Thrown at src/libuilogic/AutoTranslate/GoogleTranslateV2.cs:85
catch
{
// ignore
}
}
if ((int)result.StatusCode == 400)
{
throw new Exception("API key invalid (or perhaps billing is not enabled)?");
}
if ((int)result.StatusCode == 403)
{
throw new Exception("\"Perhaps billing is not enabled (or API key is invalid)?\"");
}
if (!result.IsSuccessStatusCode)
{
throw new Exception($"An error occurred calling GT translate - status code: {result.StatusCode}");
}
content = await result.Content.ReadAsStringAsync(cancellationToken);
}
catch (WebException webException)
{
var message = string.Empty;
if (webException.Message.Contains("(400) Bad Request"))
{
message = "API key invalid (or perhaps API/billing is not enabled)?";
}
else if (webException.Message.Contains("(403) Forbidden."))
{
message = "Perhaps billing is not enabled (or API not enabled or API key is invalid)?";
}
throw new Exception(message, webException);
}View on GitHub (pinned to 17a9f07487)
Solutions
- For 429: reduce request rate or batch size; the GCP quotas page shows per-second limits.
- Request a quota increase in the GCP console for the Translation API.
- For 5xx: retry with exponential backoff.
- Inspect the exact status code in the message to pick the right response.
Example fix
// before
if (!result.IsSuccessStatusCode)
{
throw new Exception($"An error occurred calling GT translate - status code: {result.StatusCode}");
}
// after - include the response body (already captured in Error) and special-case 429
if (!result.IsSuccessStatusCode)
{
if ((int)result.StatusCode == 429)
{
throw new Exception("GoogleTranslateV2 rate limit (429) exceeded - slow down or request a quota increase.");
}
throw new Exception($"An error occurred calling GT translate - status code: {result.StatusCode}. Body: {Error}");
} Defensive patterns
Strategy: retry
Validate before calling
// Pre-check daily/per-100s quota via the projects API (if available) or enforce a local limiter
private static readonly RateLimiter GoogleV2Limiter = new RateLimiter(perSecond: 50);
public async Task<string> TranslateLimited(...)
{
await GoogleV2Limiter.AcquireAsync(token);
return await googleV2.Translate(text, src, tgt, token);
} Try / catch
for (int attempt = 0; attempt < 5; attempt++)
{
try { return await googleV2.Translate(text, src, tgt, token); }
catch (Exception ex) when (ex.Message.Contains("status code: TooManyRequests"))
{
await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)), token);
continue;
}
throw;
}
throw new InvalidOperationException("GoogleTranslateV2 kept rate-limiting after backoff."); Prevention
- Stay under the per-100-second request/character quotas; batch text where possible.
- Use exponential backoff on 429 and 5xx.
- Request quota increases in GCP for production workloads.
- Log the exact status code so 429 vs 5xx can be handled differently.
When it happens
Trigger: Translate() posts; result.StatusCode is not 400, not 403, and not success. Most commonly 429 from exceeding per-100-second request/character quotas, or occasional 5xx.
Common situations: Per-100-second character or request quota exceeded (429); sustained load tripping rate limits; rare Google-side 500/503; region-specific outages.
Related errors
- {StaticName} failed with status code {(int)result.StatusCode
- API key invalid (or perhaps billing is not enabled)?
- "Perhaps billing is not enabled (or API key is invalid)?"
- API key invalid (or perhaps API/billing is not enabled)?
- Perhaps billing is not enabled (or API not enabled or API ke
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/9466a0d1e6e7a5ca.
Report an issue: GitHub.