{"record":{"id":"0c4665a3e658cc79","repo":"nopSolutions/nopCommerce","slug":"artificialintelligence-createproductfailed","errorCode":null,"errorMessage":"ArtificialIntelligence.CreateProductFailed","messagePattern":"ArtificialIntelligence\\.CreateProductFailed","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/ArtificialIntelligence/ArtificialIntelligenceService.cs","lineNumber":320,"sourceCode":"\n        if (languageId == 0)\n            languageId = _localizationSettings.DefaultAdminLanguageId;\n\n        var lang = await _languageService.GetLanguageByIdAsync(languageId);\n\n        var query = string.Format(string.IsNullOrEmpty(_artificialIntelligenceSettings.ProductDescriptionQuery) ? ArtificialIntelligenceDefaults.ProductDescriptionQuery : _artificialIntelligenceSettings.ProductDescriptionQuery, productName, keywords, toneOfVoiceInstruction, instruction, lang.Name);\n\n        try\n        {\n            var result = await _httpClient.SendQueryAsync(query);\n            return Markdown.ToHtml(result);\n        }\n        catch (Exception e)\n        {\n            var customer = await _workContext.GetCurrentCustomerAsync();\n            await _logger.ErrorAsync(e.Message, e, customer);\n\n            throw new NopException(string.Format(await _localizationService.GetResourceAsync(\"ArtificialIntelligence.CreateProductFailed\"), e.Message));\n        }\n    }\n\n    /// <summary>\n    /// Create meta tags by artificial intelligence\n    /// </summary>\n    /// <param name=\"entity\">The entity to which need to generate meta tags</param>\n    /// <param name=\"languageId\">The language identifier</param>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the generated meta tags\n    /// </returns>\n    public virtual async Task<(string metaTitle, string metaKeywords, string metaDescription)> CreateMetaTagsForLocalizedEntityAsync<TEntity>(TEntity entity, int languageId)\n        where TEntity : BaseEntity, IMetaTagsSupported, ILocalizedEntity\n    {\n        var currentMetaTitle = languageId == 0\n            ? entity.MetaTitle\n            : await _localizationService.GetLocalizedAsync(entity, mt => mt.MetaTitle, languageId, false);","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/ArtificialIntelligence/ArtificialIntelligenceService.cs#L302-L338","documentation":"CreateProductDescriptionAsync wraps its SendQueryAsync + Markdown.ToHtml call in try/catch. On any exception it logs the error then throws NopException whose message is the localized resource 'ArtificialIntelligence.CreateProductFailed' formatted with e.Message. So callers see a user-facing 'product creation failed: <inner detail>' message while the original exception (with stack) is preserved only in the log.","triggerScenarios":"Invoking AI product-description generation when SendQueryAsync fails (provider 4xx/5xx, auth, quota, timeout) or when ParseResponse/Markdown.ToHtml throws on a malformed provider response.","commonSituations":"Invalid/expired AI API key; provider rate limit/quota; network blocked to the AI endpoint; RequestTimeout too short; provider returns an unexpected JSON shape that fails ParseResponse; Markdown conversion of empty/odd output.","solutions":["Inspect the log: the full original exception (message + stack) is recorded before the wrapped throw.","Fix the underlying AI provider error — verify API key, quota, network, RequestTimeout for the configured ProviderType.","Catch the NopException in the UI layer and show the localized failure to the merchant without blocking product save.","On transient errors, retry with backoff; consider increasing RequestTimeout."],"exampleFix":"// before\nvar html = await _aiService.CreateProductDescriptionAsync(name, keywords, tone, instruction, custom, langId);\n\n// after\ntry\n{\n    var html = await _aiService.CreateProductDescriptionAsync(name, keywords, tone, instruction, custom, langId);\n}\ncatch (NopException ex)\n{\n    // show user-friendly message; do not block saving the product\n    NotifyError(ex.Message);\n}","handlingStrategy":"try-catch","validationCode":"// Validate AI settings before generating\nif (string.IsNullOrWhiteSpace(_aiSettings.Token))\n    throw new InvalidOperationException(\"AI provider API key is not configured.\");","typeGuard":null,"tryCatchPattern":"try { var html = await _aiService.CreateProductDescriptionAsync(name, keywords, tone, instruction, custom, langId); }\ncatch (NopException ex) { NotifyError(ex.Message); /* do not block product save */ }","preventionTips":["Treat AI product-description generation as optional; catch NopException in the UI.","Verify the API key/quota/network for the configured ProviderType.","Check the log for the original exception (recorded with full stack) to find root cause.","Set a sensible RequestTimeout and retry transient failures."],"tags":["ai","product","error-wrapping","external-api","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}