{"record":{"id":"76d5669cc1a6abd4","repo":"SubtitleEdit/subtitleedit","slug":"deeplxtranslate-error-statuscode-result-statusco","errorCode":null,"errorMessage":"DeepLXTranslate error: StatusCode={result.StatusCode}\n{resultContent}","messagePattern":"DeepLXTranslate error: StatusCode=(.+?)\n(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/libuilogic/AutoTranslate/DeepLXTranslate.cs","lineNumber":72,"sourceCode":"            HttpResponseMessage result = null!;\n            var resultContent = string.Empty;\n            for (var attempt = 0; attempt <= retryDelays.Length; attempt++)\n            {\n                var postContent = MakeContent(text, sourceLanguageCode, targetLanguageCode);\n                result = await _httpClient.PostAsync(\"/translate\", postContent, cancellationToken);\n                resultContent = await result.Content.ReadAsStringAsync(cancellationToken);\n\n                if (!DeepLTranslate.ShouldRetry(result, resultContent) || attempt == retryDelays.Length)\n                {\n                    break;\n                }\n\n                await Task.Delay(retryDelays[attempt], cancellationToken);\n            }\n\n            if (!result.IsSuccessStatusCode)\n            {\n                throw new Exception(\"DeepLXTranslate error: StatusCode=\" + result.StatusCode + Environment.NewLine + resultContent);\n            }\n\n            try\n            {\n                var parser = new SeJsonParser();\n                var alternatives = parser.GetArrayElementsByName(resultContent, \"alternatives\");\n                var data = string.Empty;\n                if (alternatives.Count > 0 && alternatives[0] != null)\n                {\n                    data = alternatives[0];\n                }\n\n                if (string.IsNullOrEmpty(data))\n                {\n                    var dataValues = parser.GetAllTagsByNameAsStrings(resultContent, \"data\");\n                    if (dataValues.Count > 0)\n                    {\n                        data = dataValues[0];","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libuilogic/AutoTranslate/DeepLXTranslate.cs#L54-L90","documentation":"Thrown by the DeepLX translator (a self-hosted reverse-engineering of DeepL, default http://localhost:1188) when the POST to /translate returns a non-success status after retries. The status code and body are surfaced. Unlike the official DeepL, DeepLX depends on a local service that scrapes DeepL's web endpoint.","triggerScenarios":"Translate() posts JSON {source_lang, target_lang, text} to the configured DeepLX URL /translate; ShouldRetry only handles 429/503, so any other non-success (404, 500, 502) lands here immediately. Most often the local DeepLX service is down, misconfigured, or blocked upstream.","commonSituations":"DeepLX docker/process not running on the configured port; wrong AutoTranslateDeepLXUrl in settings (still localhost when service is remote, or vice versa); DeepLX itself returning 500 because DeepL's web endpoint rate-limited or blocked the DeepLX IP; CORS/network egress blocked.","solutions":["Confirm the DeepLX service is up: curl the configured URL + /translate with a sample payload.","Verify Configuration.Settings.Tools.AutoTranslateDeepLXUrl matches where DeepLX actually listens (default http://localhost:1188).","Restart DeepLX and check its own logs for upstream DeepL blocks.","If running DeepLX remotely, ensure the host can reach it and the port is open."],"exampleFix":"// before\nif (!result.IsSuccessStatusCode)\n{\n    throw new Exception(\"DeepLXTranslate error: StatusCode=\" + result.StatusCode + Environment.NewLine + resultContent);\n}\n\n// after - distinguish connectivity (502/503) from DeepLX-internal errors (500) to guide the user\nif (!result.IsSuccessStatusCode)\n{\n    var hint = (int)result.StatusCode >= 500\n        ? \"DeepLX server error - is the DeepLX service running and reachable at \" + _apiUrl + \"?\"\n        : \"DeepLX returned \" + (int)result.StatusCode + \" - check the request payload and DeepLX config.\";\n    throw new Exception(\"DeepLXTranslate error: \" + hint + Environment.NewLine + \"StatusCode=\" + result.StatusCode + Environment.NewLine + resultContent);\n}","handlingStrategy":"validation","validationCode":"// Before translating, confirm the DeepLX service is reachable\nvar url = Configuration.Settings.Tools.AutoTranslateDeepLXUrl;\nif (string.IsNullOrWhiteSpace(url))\n    throw new InvalidOperationException(\"DeepLX URL is not configured.\");\nusing var probe = new HttpClient { Timeout = TimeSpan.FromSeconds(3) };\ntry\n{\n    var resp = await probe.GetAsync(url.TrimEnd('/') + \"/translate\");\n}\ncatch (Exception ex)\n{\n    throw new InvalidOperationException($\"DeepLX service at {url} is not reachable: {ex.Message}\");\n}","typeGuard":"public static async Task<bool> IsDeepLXReachableAsync(string url)\n{\n    if (string.IsNullOrWhiteSpace(url)) return false;\n    using var c = new HttpClient { Timeout = TimeSpan.FromSeconds(3) };\n    try { await c.GetAsync(url.TrimEnd('/')); return true; } catch { return false; }\n}","tryCatchPattern":"try\n{\n    return await deepLX.Translate(text, src, tgt, token);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"DeepLXTranslate error\"))\n{\n    throw new InvalidOperationException($\"DeepLX at {deepLXUrl} returned an error - confirm the service is running. Inner: {ex.Message}\", ex);\n}","preventionTips":["Run DeepLX as a managed service/daemon so it auto-restarts.","Health-check the DeepLX URL on translator selection, not just at translate time.","Keep DeepLX on the version this client's parser supports.","Log the configured URL in failures so operators know which instance was hit."],"tags":["network","self-hosted","translation","deeplx","configuration"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}