{"record":{"id":"f95ed3598fc6febf","repo":"SubtitleEdit/subtitleedit","slug":"deepl-failed-with-status-code-int-result-statusc","errorCode":null,"errorMessage":"DeepL failed with status code {(int)result.StatusCode} ({result.StatusCode})\n\n {resultContent}","messagePattern":"DeepL failed with status code (.+?) \\((.+?)\\)\n\n (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/libuilogic/AutoTranslate/DeepLTranslate.cs","lineNumber":187,"sourceCode":"                if (!ShouldRetry(result, resultContent) || attempt == retryDelays.Length)\n                {\n                    break;\n                }\n\n                await Task.Delay(retryDelays[attempt], cancellationToken);\n            }\n\n            if (result.StatusCode == HttpStatusCode.Forbidden)\n            {\n                Error = resultContent;\n                throw new Exception(\"Forbidden! \" + Environment.NewLine + Environment.NewLine + resultContent);\n            }\n\n            if (!result.IsSuccessStatusCode)\n            {\n                Error = resultContent;\n                SeLogger.Error(\"DeepLTranslate error: \" + resultContent);\n                throw new Exception($\"DeepL failed with status code {(int)result.StatusCode} ({result.StatusCode})\" + Environment.NewLine + Environment.NewLine + resultContent);\n            }\n\n            try\n            {\n                var resultList = new List<string>();\n                var parser = new JsonParser();\n                var x = (Dictionary<string, object>)parser.Parse(resultContent);\n                foreach (var k in x.Keys)\n                {\n                    if (x[k] is List<object> mainList)\n                    {\n                        foreach (var mainListItem in mainList)\n                        {\n                            if (mainListItem is Dictionary<string, object> innerDic)\n                            {\n                                foreach (var transItem in innerDic.Keys)\n                                {\n                                    if (transItem == \"text\")","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libuilogic/AutoTranslate/DeepLTranslate.cs#L169-L205","documentation":"Thrown by DeepLTranslate when the response is not success and not 403 (which is handled separately). Covers 4xx errors like 400 Bad Request / 413 Payload Too Large / 456 Quota exceeded, and 5xx server errors after retries failed. The status code, enum name, and response body are all included.","triggerScenarios":"Translate() retries on 429/503 only (see ShouldRetry, DeepLTranslate.cs:225-232); any other non-success status breaks out of the loop immediately and lands here. DeepL-specific 456 (quota exceeded) and 400 (malformed request) are common hits.","commonSituations":"DeepL 456 quota exceeded (monthly character limit hit); 400 from invalid language codes or a request body that exceeds limits; transient 5xx that did not match the retry filter; proxy returning an unexpected status.","solutions":["Read the numeric code: 456 = raise DeepL plan quota; 400 = fix the request (language codes, text length); 5xx = retry later or switch endpoint.","Verify source/target language codes are in DeepLTranslate.GetTranslationPairs (DeepLTranslate.cs:100-150).","Check the DeepL dashboard usage page for quota status.","Inspect the full resultContent in the message for DeepL's own error JSON."],"exampleFix":"// before\nSeLogger.Error(\"DeepLTranslate error: \" + resultContent);\nthrow new Exception($\"DeepL failed with status code {(int)result.StatusCode} ({result.StatusCode})\" + Environment.NewLine + Environment.NewLine + resultContent);\n\n// after - branch on DeepL's documented 456 quota code so the user sees a clear cause\nif ((int)result.StatusCode == 456)\n{\n    throw new Exception(\"DeepL quota exceeded (456) - upgrade your plan or wait for the quota reset.\" + Environment.NewLine + Environment.NewLine + resultContent);\n}\nthrow new Exception($\"DeepL failed with status code {(int)result.StatusCode} ({result.StatusCode})\" + Environment.NewLine + Environment.NewLine + resultContent);","handlingStrategy":"retry","validationCode":"// Validate language codes are in DeepL's supported set before translating\nvar supported = deeLTranslate.GetSupportedTargetLanguages().Select(p => p.Code).ToHashSet();\nif (!supported.Contains(targetLanguageCode))\n    throw new ArgumentException($\"Target language '{targetLanguageCode}' is not supported by DeepL.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    return await deeLTranslate.Translate(text, src, tgt, token);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"DeepL failed with status code\"))\n{\n    if (ex.Message.Contains(\"456\"))\n        throw new InvalidOperationException(\"DeepL quota exceeded - upgrade the plan.\", ex);\n    if (ex.Message.Contains(\"400\"))\n        throw new InvalidOperationException(\"DeepL rejected the request - check language codes and payload.\", ex);\n    throw;\n}","preventionTips":["Monitor /v2/usage periodically to catch quota exhaustion before it yields 456.","Whitelist language codes against DeepL's supported pairs before batch runs.","Keep request sizes within DeepL's documented limits.","Log the numeric status distinctly so triage can branch on 456 vs 400 vs 5xx."],"tags":["network","api","translation","deepl","quota"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}