TechnitiumSoftware/DnsServer · error · HttpApiClientException
Invalid JSON response was received.
Error message
Invalid JSON response was received.
What it means
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.
Source
Thrown at DnsServerCore.HttpApi/HttpApiClient.cs:118
public void Dispose()
{
if (_disposed)
return;
_httpClient?.Dispose();
_disposed = true;
GC.SuppressFinalize(this);
}
#endregion
#region private
private static void CheckResponseStatus(JsonElement rootElement)
{
if (!rootElement.TryGetProperty("status", out JsonElement jsonStatus))
throw new HttpApiClientException("Invalid JSON response was received.");
string? status = jsonStatus.GetString()?.ToLowerInvariant();
switch (status)
{
case "ok":
return;
case "error":
{
Exception? innerException = null;
if (rootElement.TryGetProperty("innerErrorMessage", out JsonElement jsonInnerErrorMessage))
innerException = new HttpApiClientException(jsonInnerErrorMessage.GetString()!);
if (rootElement.TryGetProperty("errorMessage", out JsonElement jsonErrorMessage))
{
if (innerException is null)
throw new HttpApiClientException(jsonErrorMessage.GetString()!);View on GitHub (pinned to d0484b6c1e)
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.
Defensive patterns
Strategy: try-catch
Try / catch
try
{
var stats = await client.GetDashboardStatsAsync(user);
}
catch (HttpApiClientException ex) when (ex.Message == "Invalid JSON response was received.")
{
// log _serverUrl, inspect raw body separately; likely wrong endpoint/proxy
logger.LogError("API returned non-conforming JSON from {Url}", serverUrl);
throw;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unknown status value was received: {status}
- Already logged in.
- No active session exist to logout.
- Already logged in. Please create a new object to use a diffe
- No active session exists. Please login and try again.
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/30c3068c57c9618f.
Report an issue: GitHub.