Return 500 errors for missing email templates and AI prompts
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user