{"record":{"id":"30c3068c57c9618f","repo":"TechnitiumSoftware/DnsServer","slug":"invalid-json-response-was-received","errorCode":null,"errorMessage":"Invalid JSON response was received.","messagePattern":"Invalid JSON response was received\\.","errorType":"exception","errorClass":"HttpApiClientException","httpStatus":null,"severity":"error","filePath":"DnsServerCore.HttpApi/HttpApiClient.cs","lineNumber":118,"sourceCode":"        public void Dispose()\n        {\n            if (_disposed)\n                return;\n\n            _httpClient?.Dispose();\n\n            _disposed = true;\n            GC.SuppressFinalize(this);\n        }\n\n        #endregion\n\n        #region private\n\n        private static void CheckResponseStatus(JsonElement rootElement)\n        {\n            if (!rootElement.TryGetProperty(\"status\", out JsonElement jsonStatus))\n                throw new HttpApiClientException(\"Invalid JSON response was received.\");\n\n            string? status = jsonStatus.GetString()?.ToLowerInvariant();\n            switch (status)\n            {\n                case \"ok\":\n                    return;\n\n                case \"error\":\n                    {\n                        Exception? innerException = null;\n\n                        if (rootElement.TryGetProperty(\"innerErrorMessage\", out JsonElement jsonInnerErrorMessage))\n                            innerException = new HttpApiClientException(jsonInnerErrorMessage.GetString()!);\n\n                        if (rootElement.TryGetProperty(\"errorMessage\", out JsonElement jsonErrorMessage))\n                        {\n                            if (innerException is null)\n                                throw new HttpApiClientException(jsonErrorMessage.GetString()!);","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore.HttpApi/HttpApiClient.cs#L100-L136","documentation":"HttpApiClient.CheckResponseStatus expects every API response JSON to carry a top-level 'status' field. This HttpApiClientException fires when the parsed root element has no 'status' property, meaning the server returned JSON that does not conform to the API contract (or returned an unrelated page). It is the baseline 'I cannot interpret this response' signal used by all API calls.","triggerScenarios":"Any HttpApiClient method (LoginAsync, GetDashboardStatsAsync, etc.) receives an HTTP body whose JSON root lacks 'status'. Typical when the URL points at the wrong service, a proxy returns an HTML error page parsed as JSON, or the server is an incompatible/older version.","commonSituations":"Pointing _serverUrl at a non-DNS-Server host; a reverse proxy returning a 200 with an HTML login page; hitting a different major version of the DNS server with a different response schema; TLS interception rewriting the body.","solutions":["Verify _serverUrl points at the Technitium DNS Server HTTP API root (e.g. https://dns.example.com).","Inspect the raw response body (log httpResponse.Content) to see what was actually returned.","Check for reverse proxies / load balancers intercepting the request and returning non-API content.","Confirm the server version matches the HttpApiClient library version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var stats = await client.GetDashboardStatsAsync(user);\n}\ncatch (HttpApiClientException ex) when (ex.Message == \"Invalid JSON response was received.\")\n{\n    // log _serverUrl, inspect raw body separately; likely wrong endpoint/proxy\n    logger.LogError(\"API returned non-conforming JSON from {Url}\", serverUrl);\n    throw;\n}","preventionTips":["Point _serverUrl at the DNS Server API root and verify connectivity first.","Log raw response bodies during integration testing to catch proxy/HTML interposition.","Keep client and server versions aligned."],"tags":["http-api","client","json","protocol"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}