@@ -150,38 +150,8 @@ def handle_error_notifications(error, notify, report, reraise)
150150
151151 # Report to error reporting service if requested
152152 if report
153- # Get message if available
154- mailer_message = respond_to? ( :message ) ? message : nil
155-
156- # Prepare universal mailer fields
157- message_data = { }
158- MetadataCollection . add_message_metadata ( self , message_data )
159-
160- # Prepare app-specific context data
161153 context_data = { recipients : recipients ( error ) }
162- MetadataCollection . add_context_metadata ( self , context_data )
163-
164- # Extract email fields
165- to = mailer_message &.to
166- from = mailer_message &.from &.first
167- subject = mailer_message &.subject
168- message_id = extract_message_id_from_mailer ( self )
169-
170- # Create ActionMailer-specific error struct
171- exception_data = Log ::ActionMailer ::Error . new (
172- to : to ,
173- from : from ,
174- subject : subject ,
175- message_id : message_id ,
176- mailer_class : self . class . to_s ,
177- mailer_action : respond_to? ( :action_name ) ? action_name &.to_s : nil ,
178- attachment_count : message_data [ :attachment_count ] ,
179- error_class : error . class ,
180- message : error . message ,
181- backtrace : error . backtrace ,
182- additional_data : context_data . presence ,
183- timestamp : Time . now
184- )
154+ exception_data = build_exception_data ( error , Level ::Error , context_data )
185155
186156 # Log the exception with structured data
187157 LogStruct . error ( exception_data )
@@ -202,29 +172,32 @@ def handle_error_notifications(error, notify, report, reraise)
202172 # Log a notification event that can be picked up by external systems
203173 sig { params ( error : StandardError ) . void }
204174 def log_notification_event ( error )
205- # Get message if available
206- mailer_message = respond_to? ( :message ) ? message : nil
207-
208- # Prepare universal mailer fields
209- message_data = { }
210- MetadataCollection . add_message_metadata ( self , message_data )
211-
212- # Prepare app-specific context data
213175 context_data = {
214176 mailer : self . class . to_s ,
215177 action : action_name &.to_s ,
216178 recipients : recipients ( error )
217179 }
180+ exception_data = build_exception_data ( error , Level ::Info , context_data )
181+
182+ # Log the error at info level since it's not a critical error
183+ LogStruct . info ( exception_data )
184+ end
185+
186+ sig { params ( error : StandardError , level : Level , context_data : T ::Hash [ Symbol , T . untyped ] ) . returns ( Log ::ActionMailer ::Error ) }
187+ def build_exception_data ( error , level , context_data )
188+ mailer_message = respond_to? ( :message ) ? message : nil
189+
190+ message_data = { }
191+ MetadataCollection . add_message_metadata ( self , message_data )
192+
218193 MetadataCollection . add_context_metadata ( self , context_data )
219194
220- # Extract email fields
221195 to = mailer_message &.to
222196 from = mailer_message &.from &.first
223197 subject = mailer_message &.subject
224198 message_id = extract_message_id_from_mailer ( self )
225199
226- # Create ActionMailer-specific error struct
227- exception_data = Log ::ActionMailer ::Error . new (
200+ Log ::ActionMailer ::Error . new (
228201 to : to ,
229202 from : from ,
230203 subject : subject ,
@@ -237,11 +210,8 @@ def log_notification_event(error)
237210 backtrace : error . backtrace ,
238211 additional_data : context_data . presence ,
239212 timestamp : Time . now ,
240- level : Level :: Info
213+ level : level
241214 )
242-
243- # Log the error at info level since it's not a critical error
244- LogStruct . info ( exception_data )
245215 end
246216
247217 sig { params ( error : StandardError ) . returns ( String ) }
0 commit comments