nopSolutions/nopCommerce · error · NopException
Item HS classification error: response content invalid
Error message
Item HS classification error: response content invalid - {ex.Message} What it means
Thrown when JsonConvert.DeserializeObject<TResponse> throws while parsing the HS classification HTTP response body. The raw responseString could not be deserialized into the expected TResponse type, so the response is treated as invalid.
Solutions
- Log responseString and httpResponse.StatusCode to see the actual payload that failed to deserialize.
- Check for Avalara service status / maintenance windows if the body is an HTML error page.
- Update the Avalara ItemClassificationHttpClient and response models to match the current API schema.
Example fix
// before
try
{
result = JsonConvert.DeserializeObject<TResponse>(responseString ?? string.Empty);
}
catch (Exception ex)
{
throw new NopException($"Item HS classification error: response content invalid - {ex.Message}");
}
// after — include status code and a body snippet for diagnosis
if (!httpResponse.IsSuccessStatusCode)
throw new NopException($"Item HS classification HTTP {(int)httpResponse.StatusCode} {httpResponse.StatusCode}: {Truncate(responseString, 500)}");
try { result = JsonConvert.DeserializeObject<TResponse>(responseString ?? string.Empty); }
catch (Exception ex)
{
throw new NopException($"Item HS classification error: response content invalid - {ex.Message}; body: {Truncate(responseString, 500)}", ex);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!httpResponse.IsSuccessStatusCode)
throw new NopException($"HS classification HTTP {(int)httpResponse.StatusCode}: {Truncate(responseString, 500)}"); Type guard
static bool IsJsonBody(string body) => !string.IsNullOrWhiteSpace(body) && body.TrimStart().StartsWith("{") || body.TrimStart().StartsWith("["); Try / catch
try { return await client.RequestAsync<TReq,TResp>(request); }
catch (NopException ex) when (ex.Message.Contains("response content invalid"))
{ _logger.LogError(ex, "HS classification response unparseable; check Avalara status"); throw; } Prevention
- Check HTTP status before deserializing and fail with a clear message on non-2xx.
- Log a truncated body snippet on parse failure for diagnostics.
- Keep the Avalara SDK and response models in sync with the live API.
When it happens
Trigger: Avalara HS classification API returns a non-JSON body (HTML error page, empty body, gateway error text); the response schema changed and no longer matches TResponse; a 5xx with a plain-text body.
Common situations: Avalara API outage returning an HTML maintenance page; reverse proxy/CDN intercepting the request and returning an error page; SDK version out of date with the live Avalara API contract.
Related errors
- Item HS classification error
- AccountId not set
- LicenseKey is not set
- - Debug ID
- Failed to delete customer
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/959a24edb2adc2f5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Plugins/Nop.Plugin.Tax.Avalara/Services/ItemClassificationHttpClient.cs:97
//add authorization
var securityToken = PrepareSecurity();
//call PrepareSecurity
requestMessage.Headers.Add(HeaderNames.Authorization, $"Basic {securityToken}");
var httpResponse = await _httpClient.SendAsync(requestMessage);
//return result
TResponse result = null;
var responseString = await httpResponse.Content.ReadAsStringAsync();
try
{
result = JsonConvert.DeserializeObject<TResponse>(responseString ?? string.Empty);
}
catch (Exception ex)
{
throw new NopException($"Item HS classification error: response content invalid - {ex.Message}");
}
if (!string.IsNullOrEmpty(result?.Error?.Code))
{
var error = result.Error.Code;
if (result.Error.Details?.Any() ?? false)
error += result.Error.Details.Aggregate(string.Empty, (text, e) => $"{text}{e.Message} {e.Description};{Environment.NewLine}");
throw new NopException($"Item HS classification error: {error}");
}
return result;
}
catch (AggregateException exception)
{
//rethrow actual exception
throw exception.InnerException;
}
}View on GitHub (pinned to 64bdf2ff08)