{"record":{"id":"959a24edb2adc2f5","repo":"nopSolutions/nopCommerce","slug":"item-hs-classification-error-response-content-inv","errorCode":null,"errorMessage":"Item HS classification error: response content invalid - {ex.Message}","messagePattern":"Item HS classification error: response content invalid - (.+?)","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Plugins/Nop.Plugin.Tax.Avalara/Services/ItemClassificationHttpClient.cs","lineNumber":97,"sourceCode":"\n            //add authorization\n            var securityToken = PrepareSecurity();\n\n            //call PrepareSecurity\n            requestMessage.Headers.Add(HeaderNames.Authorization, $\"Basic {securityToken}\");\n\n            var httpResponse = await _httpClient.SendAsync(requestMessage);\n\n            //return result\n            TResponse result = null;\n            var responseString = await httpResponse.Content.ReadAsStringAsync();\n            try\n            {\n                result = JsonConvert.DeserializeObject<TResponse>(responseString ?? string.Empty);\n            }\n            catch (Exception ex)\n            {\n                throw new NopException($\"Item HS classification error: response content invalid - {ex.Message}\");\n            }\n            if (!string.IsNullOrEmpty(result?.Error?.Code))\n            {\n                var error = result.Error.Code;\n                if (result.Error.Details?.Any() ?? false)\n                    error += result.Error.Details.Aggregate(string.Empty, (text, e) => $\"{text}{e.Message} {e.Description};{Environment.NewLine}\");\n\n                throw new NopException($\"Item HS classification error: {error}\");\n            }\n\n            return result;\n        }\n        catch (AggregateException exception)\n        {\n            //rethrow actual exception\n            throw exception.InnerException;\n        }\n    }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Plugins/Nop.Plugin.Tax.Avalara/Services/ItemClassificationHttpClient.cs#L79-L115","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ntry\n{\n    result = JsonConvert.DeserializeObject<TResponse>(responseString ?? string.Empty);\n}\ncatch (Exception ex)\n{\n    throw new NopException($\"Item HS classification error: response content invalid - {ex.Message}\");\n}\n\n// after — include status code and a body snippet for diagnosis\nif (!httpResponse.IsSuccessStatusCode)\n    throw new NopException($\"Item HS classification HTTP {(int)httpResponse.StatusCode} {httpResponse.StatusCode}: {Truncate(responseString, 500)}\");\ntry { result = JsonConvert.DeserializeObject<TResponse>(responseString ?? string.Empty); }\ncatch (Exception ex)\n{\n    throw new NopException($\"Item HS classification error: response content invalid - {ex.Message}; body: {Truncate(responseString, 500)}\", ex);\n}","handlingStrategy":"try-catch","validationCode":"if (!httpResponse.IsSuccessStatusCode)\n    throw new NopException($\"HS classification HTTP {(int)httpResponse.StatusCode}: {Truncate(responseString, 500)}\");","typeGuard":"static bool IsJsonBody(string body) => !string.IsNullOrWhiteSpace(body) && body.TrimStart().StartsWith(\"{\") || body.TrimStart().StartsWith(\"[\");","tryCatchPattern":"try { return await client.RequestAsync<TReq,TResp>(request); }\ncatch (NopException ex) when (ex.Message.Contains(\"response content invalid\"))\n{ _logger.LogError(ex, \"HS classification response unparseable; check Avalara status\"); throw; }","preventionTips":["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."],"tags":["avalara","hs-classification","deserialization","api-error","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}