{"record":{"id":"012fe5e1645e35ea","repo":"nopSolutions/nopCommerce","slug":"httpresponse-reasonphrase","errorCode":null,"errorMessage":"{httpResponse.ReasonPhrase}","messagePattern":"\\{httpResponse\\.ReasonPhrase\\}","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/ArtificialIntelligence/ArtificialIntelligenceHttpClient.cs","lineNumber":78,"sourceCode":"    public virtual async Task<string> SendQueryAsync(string query)\n    {\n        var request = _artificialIntelligenceHttpClientHelper.CreateRequest(_artificialIntelligenceSettings, query);\n        \n        var httpResponse = await _httpClient.SendAsync(request);\n        var response = await httpResponse.Content.ReadAsStringAsync();\n\n        var log = new StringBuilder($\"AI {_artificialIntelligenceSettings.ProviderType.ToString()} request: {request}{Environment.NewLine}\");\n\n        if (!httpResponse.IsSuccessStatusCode)\n        {\n            if (_artificialIntelligenceSettings.LogRequests)\n            {\n                await appendBaseInfo();\n\n                await _logger.InsertLogAsync(LogLevel.Information, $\"AI {_artificialIntelligenceSettings.ProviderType.ToString()} request\", log.ToString());\n            }\n\n            throw new NopException(httpResponse.ReasonPhrase, innerException: new Exception(response));\n        }\n\n        var result  = _artificialIntelligenceHttpClientHelper.ParseResponse(response);\n\n        if (!_artificialIntelligenceSettings.LogRequests) \n            return result;\n\n        var tokensInfo = _artificialIntelligenceHttpClientHelper.GetTokensInfo(response);\n\n        log.AppendLine(\"Tokens info:\");\n        log.AppendLine(tokensInfo);\n        await appendBaseInfo();\n\n        await _logger.InsertLogAsync(LogLevel.Information, $\"AI {_artificialIntelligenceSettings.ProviderType.ToString()} request ({tokensInfo.Replace(Environment.NewLine, \", \")})\",  log.ToString());\n\n        return result;\n\n        async Task appendBaseInfo()","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/ArtificialIntelligence/ArtificialIntelligenceHttpClient.cs#L60-L96","documentation":"In ArtificialIntelligenceHttpClient.SendQueryAsync, after sending the AI request, if httpResponse.IsSuccessStatusCode is false the method throws NopException using httpResponse.ReasonPhrase as the message and nests the raw response body as the innerException. This surfaces provider errors (4xx/5xx) from Gemini/ChatGPT/DeepSeek endpoints, e.g. auth failure, rate limit, quota, malformed request.","triggerScenarios":"Calling SendQueryAsync(query) and the AI provider returns a non-2xx status: invalid/expired API key (401), forbidden (403), rate limited (429), bad request payload (400), or provider server error (5xx). The timeout configured from ArtificialIntelligenceSettings.RequestTimeout may also produce failures upstream.","commonSituations":"Wrong or expired API key in ArtificialIntelligenceSettings; exceeding provider quota/rate limit; network egress blocked to the AI endpoint; request payload larger than provider limits; provider outage; RequestTimeout too short for long generations.","solutions":["Verify the API key/token and endpoint configuration in ArtificialIntelligenceSettings for the chosen ProviderType.","Inspect the innerException (raw response body) for the provider's specific error — it usually names the cause (auth, quota, model).","On 429/quota errors, back off and retry with exponential delay; consider RequestTimeout increase.","Confirm network/firewall allows outbound HTTPS to the provider host.","Enable LogRequests to capture full request/response in the log for diagnosis."],"exampleFix":"// before\nvar result = await _httpClient.SendQueryAsync(query);\n\n// after\ntry\n{\n    var result = await _httpClient.SendQueryAsync(query);\n}\ncatch (NopException ex) when (ex.InnerException is Exception raw)\n{\n    _logger.ErrorAsync($\"AI request failed: {ex.Message}. Provider response: {raw.Message}\", ex, customer);\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"// Validate AI settings before sending\nif (string.IsNullOrWhiteSpace(_aiSettings.Token) /* or key field per provider */)\n    throw new InvalidOperationException(\"AI provider API key is not configured.\");","typeGuard":null,"tryCatchPattern":"try { var result = await _httpClient.SendQueryAsync(query); }\ncatch (NopException ex) when (ex.InnerException is Exception raw)\n{\n    // ex.Message == ReasonPhrase; raw.Message == response body\n    _logger.ErrorAsync($\"AI call failed: {ex.Message}. Body: {raw.Message}\", ex, customer);\n    throw;\n}","preventionTips":["Verify the API key/token for the selected ProviderType before invoking AI.","Enable LogRequests to capture full request/response for failed calls.","Set a sensible RequestTimeout; implement backoff for 429/quota responses.","Confirm outbound network/firewall access to the provider host."],"tags":["ai","http","external-api","network","configuration","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}