Skip to content

Commit 12298e4

Browse files
committed
tejas commnets
1 parent eff2832 commit 12298e4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/spam/email_checker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import re
33
from html import unescape
4+
from openai import OpenAIError
45
from typing import Optional, Union
56

67
from src.render.main import MessageDef, render_email
@@ -59,7 +60,7 @@ async def check_spam(self, m: EmailSendModel):
5960

6061
try:
6162
spam_result = await self.spam_service.is_spam_email(email_info, company_name)
62-
# Cache all results (both spam and non-spam)
63+
# Cache all results (both spam and non-spam) - only when successful
6364
await self.cache_service.set(m, spam_result)
6465

6566
if spam_result.spam:
@@ -74,10 +75,10 @@ async def check_spam(self, m: EmailSendModel):
7475
"email_main_body": _clean_html_body(context.get('main_message__render')) or 'no main body',
7576
},
7677
)
77-
except Exception as e:
78+
except OpenAIError as e:
7879
# Use the same logging structure for consistency
7980
logger.error(
80-
"Error during spam check",
81+
"LLM Provider Error during spam check",
8182
extra={
8283
"reason": str(e),
8384
"subject": email_info.subject,

tests/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,10 @@ class FakeResponse:
309309
# Create a fake client with a mocked responses.parse method
310310
fake_client = AsyncMock()
311311
if 'spam_service_error' in request.keywords:
312-
# This will RAISE Exception when fake_client.responses.parse() is called
313-
fake_client.responses.parse.side_effect = Exception('Openai test error')
312+
# This will RAISE OpenAIError when fake_client.responses.parse() is called
313+
from openai import OpenAIError
314+
315+
fake_client.responses.parse.side_effect = OpenAIError('Openai test error')
314316
else:
315317
fake_client.responses.parse.return_value = FakeResponse()
316318

0 commit comments

Comments
 (0)