nopSolutions/nopCommerce · error · NopException

{httpResponse.ReasonPhrase}

Error message

{httpResponse.ReasonPhrase}

What it means

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.

Source

Thrown at src/Libraries/Nop.Services/ArtificialIntelligence/ArtificialIntelligenceHttpClient.cs:78

    public virtual async Task<string> SendQueryAsync(string query)
    {
        var request = _artificialIntelligenceHttpClientHelper.CreateRequest(_artificialIntelligenceSettings, query);
        
        var httpResponse = await _httpClient.SendAsync(request);
        var response = await httpResponse.Content.ReadAsStringAsync();

        var log = new StringBuilder($"AI {_artificialIntelligenceSettings.ProviderType.ToString()} request: {request}{Environment.NewLine}");

        if (!httpResponse.IsSuccessStatusCode)
        {
            if (_artificialIntelligenceSettings.LogRequests)
            {
                await appendBaseInfo();

                await _logger.InsertLogAsync(LogLevel.Information, $"AI {_artificialIntelligenceSettings.ProviderType.ToString()} request", log.ToString());
            }

            throw new NopException(httpResponse.ReasonPhrase, innerException: new Exception(response));
        }

        var result  = _artificialIntelligenceHttpClientHelper.ParseResponse(response);

        if (!_artificialIntelligenceSettings.LogRequests) 
            return result;

        var tokensInfo = _artificialIntelligenceHttpClientHelper.GetTokensInfo(response);

        log.AppendLine("Tokens info:");
        log.AppendLine(tokensInfo);
        await appendBaseInfo();

        await _logger.InsertLogAsync(LogLevel.Information, $"AI {_artificialIntelligenceSettings.ProviderType.ToString()} request ({tokensInfo.Replace(Environment.NewLine, ", ")})",  log.ToString());

        return result;

        async Task appendBaseInfo()

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Verify the API key/token and endpoint configuration in ArtificialIntelligenceSettings for the chosen ProviderType.
  2. Inspect the innerException (raw response body) for the provider's specific error — it usually names the cause (auth, quota, model).
  3. On 429/quota errors, back off and retry with exponential delay; consider RequestTimeout increase.
  4. Confirm network/firewall allows outbound HTTPS to the provider host.
  5. Enable LogRequests to capture full request/response in the log for diagnosis.

Example fix

// before
var result = await _httpClient.SendQueryAsync(query);

// after
try
{
    var result = await _httpClient.SendQueryAsync(query);
}
catch (NopException ex) when (ex.InnerException is Exception raw)
{
    _logger.ErrorAsync($"AI request failed: {ex.Message}. Provider response: {raw.Message}", ex, customer);
    throw;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate AI settings before sending
if (string.IsNullOrWhiteSpace(_aiSettings.Token) /* or key field per provider */)
    throw new InvalidOperationException("AI provider API key is not configured.");

Try / catch

try { var result = await _httpClient.SendQueryAsync(query); }
catch (NopException ex) when (ex.InnerException is Exception raw)
{
    // ex.Message == ReasonPhrase; raw.Message == response body
    _logger.ErrorAsync($"AI call failed: {ex.Message}. Body: {raw.Message}", ex, customer);
    throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/012fe5e1645e35ea. Report an issue: GitHub.