Skip to content

Commit c3c53ca

Browse files
Catch individual email delivery exceptions (#1670)
1 parent 846dfe4 commit c3c53ca

File tree

2 files changed

+135
-101
lines changed

2 files changed

+135
-101
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ developers to maintain and readjust their custom modifications on the main proje
1010
- Fix the GTag script URL html rendering (#1666)
1111
- Fix the "Load More" JS error in secretaries page (#1677)
1212
- Fix the PHP compatibility error of the appointments index API endpoint (#1678)
13-
13+
- Catch individual email delivery exceptions (#1670)
1414

1515

1616

application/libraries/Notifications.php

+134-100
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,23 @@ public function notify_appointment_saved(
8080
$subject = $manage_mode ? lang('appointment_details_changed') : lang('appointment_booked');
8181
$message = $manage_mode ? '' : lang('thank_you_for_appointment');
8282

83-
$this->CI->email_messages->send_appointment_saved(
84-
$appointment,
85-
$provider,
86-
$service,
87-
$customer,
88-
$settings,
89-
$subject,
90-
$message,
91-
$customer_link,
92-
$customer['email'],
93-
$ics_stream,
94-
$customer['timezone'],
95-
);
83+
try {
84+
$this->CI->email_messages->send_appointment_saved(
85+
$appointment,
86+
$provider,
87+
$service,
88+
$customer,
89+
$settings,
90+
$subject,
91+
$message,
92+
$customer_link,
93+
$customer['email'],
94+
$ics_stream,
95+
$customer['timezone'],
96+
);
97+
} catch (Throwable $e) {
98+
$this->log_exception($e, 'appointment-saved to customer', $appointment['id'] ?? null);
99+
}
96100
}
97101

98102
// Notify provider.
@@ -107,19 +111,23 @@ public function notify_appointment_saved(
107111
$subject = $manage_mode ? lang('appointment_details_changed') : lang('appointment_added_to_your_plan');
108112
$message = $manage_mode ? '' : lang('appointment_link_description');
109113

110-
$this->CI->email_messages->send_appointment_saved(
111-
$appointment,
112-
$provider,
113-
$service,
114-
$customer,
115-
$settings,
116-
$subject,
117-
$message,
118-
$provider_link,
119-
$provider['email'],
120-
$ics_stream,
121-
$provider['timezone'],
122-
);
114+
try {
115+
$this->CI->email_messages->send_appointment_saved(
116+
$appointment,
117+
$provider,
118+
$service,
119+
$customer,
120+
$settings,
121+
$subject,
122+
$message,
123+
$provider_link,
124+
$provider['email'],
125+
$ics_stream,
126+
$provider['timezone'],
127+
);
128+
} catch (Throwable $e) {
129+
$this->log_exception($e, 'appointment-saved to provider', $appointment['id'] ?? null);
130+
}
123131
}
124132

125133
// Notify admins.
@@ -135,19 +143,23 @@ public function notify_appointment_saved(
135143
$subject = $manage_mode ? lang('appointment_details_changed') : lang('appointment_added_to_your_plan');
136144
$message = $manage_mode ? '' : lang('appointment_link_description');
137145

138-
$this->CI->email_messages->send_appointment_saved(
139-
$appointment,
140-
$provider,
141-
$service,
142-
$customer,
143-
$settings,
144-
$subject,
145-
$message,
146-
$provider_link,
147-
$admin['email'],
148-
$ics_stream,
149-
$admin['timezone'],
150-
);
146+
try {
147+
$this->CI->email_messages->send_appointment_saved(
148+
$appointment,
149+
$provider,
150+
$service,
151+
$customer,
152+
$settings,
153+
$subject,
154+
$message,
155+
$provider_link,
156+
$admin['email'],
157+
$ics_stream,
158+
$admin['timezone'],
159+
);
160+
} catch (Throwable $e) {
161+
$this->log_exception($e, 'appointment-saved to admin', $appointment['id'] ?? null);
162+
}
151163
}
152164

153165
// Notify secretaries.
@@ -167,29 +179,26 @@ public function notify_appointment_saved(
167179
$subject = $manage_mode ? lang('appointment_details_changed') : lang('appointment_added_to_your_plan');
168180
$message = $manage_mode ? '' : lang('appointment_link_description');
169181

170-
$this->CI->email_messages->send_appointment_saved(
171-
$appointment,
172-
$provider,
173-
$service,
174-
$customer,
175-
$settings,
176-
$subject,
177-
$message,
178-
$provider_link,
179-
$secretary['email'],
180-
$ics_stream,
181-
$secretary['timezone'],
182-
);
182+
try {
183+
$this->CI->email_messages->send_appointment_saved(
184+
$appointment,
185+
$provider,
186+
$service,
187+
$customer,
188+
$settings,
189+
$subject,
190+
$message,
191+
$provider_link,
192+
$secretary['email'],
193+
$ics_stream,
194+
$secretary['timezone'],
195+
);
196+
} catch (Throwable $e) {
197+
$this->log_exception($e, 'appointment-saved to secretary', $appointment['id'] ?? null);
198+
}
183199
}
184200
} catch (Throwable $e) {
185-
log_message(
186-
'error',
187-
'Notifications - Could not email confirmation details of appointment (' .
188-
($appointment['id'] ?? '-') .
189-
') : ' .
190-
$e->getMessage(),
191-
);
192-
log_message('error', $e->getTraceAsString());
201+
$this->log_exception($e, 'appointment-saved (general exception)', $appointment['id'] ?? null);
193202
} finally {
194203
config(['language' => $current_language ?? 'english']);
195204
$this->CI->lang->load('translations');
@@ -226,16 +235,20 @@ public function notify_appointment_deleted(
226235
config(['language' => $provider['language']]);
227236
$this->CI->lang->load('translations');
228237

229-
$this->CI->email_messages->send_appointment_deleted(
230-
$appointment,
231-
$provider,
232-
$service,
233-
$customer,
234-
$settings,
235-
$provider['email'],
236-
$cancellation_reason,
237-
$provider['timezone'],
238-
);
238+
try {
239+
$this->CI->email_messages->send_appointment_deleted(
240+
$appointment,
241+
$provider,
242+
$service,
243+
$customer,
244+
$settings,
245+
$provider['email'],
246+
$cancellation_reason,
247+
$provider['timezone'],
248+
);
249+
} catch (Throwable $e) {
250+
$this->log_exception($e, 'appointment-deleted to provider', $appointment['id'] ?? null);
251+
}
239252
}
240253

241254
// Notify customer.
@@ -246,16 +259,20 @@ public function notify_appointment_deleted(
246259
config(['language' => $customer['language']]);
247260
$this->CI->lang->load('translations');
248261

249-
$this->CI->email_messages->send_appointment_deleted(
250-
$appointment,
251-
$provider,
252-
$service,
253-
$customer,
254-
$settings,
255-
$customer['email'],
256-
$cancellation_reason,
257-
$customer['timezone'],
258-
);
262+
try {
263+
$this->CI->email_messages->send_appointment_deleted(
264+
$appointment,
265+
$provider,
266+
$service,
267+
$customer,
268+
$settings,
269+
$customer['email'],
270+
$cancellation_reason,
271+
$customer['timezone'],
272+
);
273+
} catch (Throwable $e) {
274+
$this->log_exception($e, 'appointment-deleted to customer', $appointment['id'] ?? null);
275+
}
259276
}
260277

261278
// Notify admins.
@@ -269,16 +286,20 @@ public function notify_appointment_deleted(
269286
config(['language' => $admin['language']]);
270287
$this->CI->lang->load('translations');
271288

272-
$this->CI->email_messages->send_appointment_deleted(
273-
$appointment,
274-
$provider,
275-
$service,
276-
$customer,
277-
$settings,
278-
$admin['email'],
279-
$cancellation_reason,
280-
$admin['timezone'],
281-
);
289+
try {
290+
$this->CI->email_messages->send_appointment_deleted(
291+
$appointment,
292+
$provider,
293+
$service,
294+
$customer,
295+
$settings,
296+
$admin['email'],
297+
$cancellation_reason,
298+
$admin['timezone'],
299+
);
300+
} catch (Throwable $e) {
301+
$this->log_exception($e, 'appointment-deleted to admin', $appointment['id'] ?? null);
302+
}
282303
}
283304

284305
// Notify secretaries.
@@ -296,16 +317,20 @@ public function notify_appointment_deleted(
296317
config(['language' => $secretary['language']]);
297318
$this->CI->lang->load('translations');
298319

299-
$this->CI->email_messages->send_appointment_deleted(
300-
$appointment,
301-
$provider,
302-
$service,
303-
$customer,
304-
$settings,
305-
$secretary['email'],
306-
$cancellation_reason,
307-
$secretary['timezone'],
308-
);
320+
try {
321+
$this->CI->email_messages->send_appointment_deleted(
322+
$appointment,
323+
$provider,
324+
$service,
325+
$customer,
326+
$settings,
327+
$secretary['email'],
328+
$cancellation_reason,
329+
$secretary['timezone'],
330+
);
331+
} catch (Throwable $e) {
332+
$this->log_exception($e, 'appointment-deleted to secretary', $appointment['id'] ?? null);
333+
}
309334
}
310335
} catch (Throwable $e) {
311336
log_message(
@@ -321,4 +346,13 @@ public function notify_appointment_deleted(
321346
$this->CI->lang->load('translations');
322347
}
323348
}
349+
350+
private function log_exception(Throwable $e, string $message, ?int $appointment_id): void
351+
{
352+
log_message(
353+
'error',
354+
'Notifications - Could not email ' . $message . ' (' . ($appointment_id ?? '-') . ') : ' . $e->getMessage(),
355+
);
356+
log_message('error', $e->getTraceAsString());
357+
}
324358
}

0 commit comments

Comments
 (0)