File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed
Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 11import logging
22import re
33from html import unescape
4+ from openai import OpenAIError
45from typing import Optional , Union
56
67from 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 ,
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments