From b114156e9cd98a194e0eca2e3b696dd74c272e6f Mon Sep 17 00:00:00 2001 From: claude Date: Mon, 1 Jun 2026 16:58:11 +0300 Subject: [PATCH] Return 500 errors for missing email templates and AI prompts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed configuration error handling to throw InvalidOperationException instead of silently using fallback values. This ensures: 1. Missing email templates (critical config) → 500 error to UI 2. Missing AI prompts (critical config) → 500 error to UI 3. Clear error messages indicating config issue 4. Prompts administrators to check database seeding Services updated: - EmailTemplateService.Get() throws for missing template - CvMatcherService.ScorePairAsync() throws for missing AI prompt This prevents silent failures with degraded service quality and makes it obvious to users that the system has a configuration problem that needs fixing. Co-Authored-By: Claude Haiku 4.5 --- Apis/cv-matcher-api/Services/CvMatcherService.cs | 6 +++--- Apis/email-data/Services/EmailTemplateService.cs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Apis/cv-matcher-api/Services/CvMatcherService.cs b/Apis/cv-matcher-api/Services/CvMatcherService.cs index 2c8ac17..a35f8fe 100644 --- a/Apis/cv-matcher-api/Services/CvMatcherService.cs +++ b/Apis/cv-matcher-api/Services/CvMatcherService.cs @@ -125,9 +125,9 @@ public sealed class CvMatcherService : ICvMatcherService var evidence = evidenceChunks.Count > 0 ? string.Join("\n\n", evidenceChunks.Take(4)) : Limit(job.Text, 4000); var systemPrompt = await _aiPrompts.GetAsync("ai.cv-match.system-prompt", language, ct) - ?? (language == "ro" - ? "Ești un motor strict de potrivire CV-job. Returnează doar JSON. Punctează realist între 0 și 100." - : "You are a strict CV-to-job matching engine. Return JSON only. Score realistically from 0 to 100."); + ?? throw new InvalidOperationException( + $"AI prompt not found: key='ai.cv-match.system-prompt', language='{language}'. " + + $"This is a configuration error. Ensure the cvMatcher.AiPrompts table is properly seeded with language-specific prompts."); var userPrompt = $""" CV: diff --git a/Apis/email-data/Services/EmailTemplateService.cs b/Apis/email-data/Services/EmailTemplateService.cs index 8cd338d..f59220b 100644 --- a/Apis/email-data/Services/EmailTemplateService.cs +++ b/Apis/email-data/Services/EmailTemplateService.cs @@ -37,8 +37,9 @@ public sealed class EmailTemplateService : IEmailTemplateService && _valueCache.TryGetValue(CacheKey(key, "en"), out var fallback)) return fallback; - _logger.LogWarning("Email template not found: key={Key}, language={Language}", key, language); - return key; + throw new InvalidOperationException( + $"Email template not found: key='{key}', language='{language}'. " + + $"This is a configuration error. Ensure the email.Templates table is properly seeded."); } ///