newsletter : handle errors
This commit is contained in:
parent
72fff85a8c
commit
f76e3d9fb3
3 changed files with 33 additions and 20 deletions
|
|
@ -16,7 +16,7 @@ return [
|
||||||
'username' => 'MS_ncQ2K5@actuel-inactuel.fr',
|
'username' => 'MS_ncQ2K5@actuel-inactuel.fr',
|
||||||
'password' => 'mssp.ou3hOyX.z86org8y2kklew13.raOTfvP',
|
'password' => 'mssp.ou3hOyX.z86org8y2kklew13.raOTfvP',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'routes' => [
|
'routes' => [
|
||||||
require __DIR__ . '/routes/virtual-category.php',
|
require __DIR__ . '/routes/virtual-category.php',
|
||||||
require __DIR__ . '/routes/subscribe.php',
|
require __DIR__ . '/routes/subscribe.php',
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,11 @@ return [
|
||||||
'name' => 'actuel-inactuel',
|
'name' => 'actuel-inactuel',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
$sentEmails = [];
|
||||||
foreach ($recipients as $recipient) {
|
$errors = [];
|
||||||
|
|
||||||
|
foreach ($recipients as $recipient) {
|
||||||
|
try {
|
||||||
$kirby->email([
|
$kirby->email([
|
||||||
'from' => $from,
|
'from' => $from,
|
||||||
'to' => $recipient,
|
'to' => $recipient,
|
||||||
|
|
@ -57,23 +60,26 @@ return [
|
||||||
'recipient' => $recipient,
|
'recipient' => $recipient,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
$sentEmails[] = $recipient;
|
||||||
|
} catch (Exception $error) {
|
||||||
|
$errors[] = [
|
||||||
|
'email' => $recipient,
|
||||||
|
'message' => $error->getMessage(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$data->isTest) {
|
|
||||||
$emailPage->changeStatus('listed');
|
|
||||||
} else {
|
|
||||||
$emailPage->changeStatus('unlisted');
|
|
||||||
}
|
|
||||||
|
|
||||||
return json_encode([
|
|
||||||
'status' => 'success',
|
|
||||||
'message' => 'Email(s) sent successfully.',
|
|
||||||
]);
|
|
||||||
} catch (Exception $error) {
|
|
||||||
return json_encode([
|
|
||||||
'status' => 'error',
|
|
||||||
'message' => $error->getMessage() . ' file ' . $error->getFile() . ' line ' . $error->getLine(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$data->isTest) {
|
||||||
|
$emailPage->changeStatus('listed');
|
||||||
|
} else {
|
||||||
|
$emailPage->changeStatus('unlisted');
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_encode([
|
||||||
|
'status' => empty($errors) ? 'success' : 'partial',
|
||||||
|
'message' => empty($errors) ? 'All emails sent successfully.' : 'Certains emails n\'ont pas pu être envoyé.',
|
||||||
|
'sent' => $sentEmails,
|
||||||
|
'failed' => $errors,
|
||||||
|
]);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,14 @@ async function send(event, isTest = false) {
|
||||||
location.href = location.href;
|
location.href = location.href;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(data.message || "Erreur inconnue");
|
let errorMessage = data.message || "Erreur inconnue";
|
||||||
|
|
||||||
|
if (data.failed && data.failed.length > 0) {
|
||||||
|
const failedEmails = data.failed.map((f) => f.email).join(", ");
|
||||||
|
errorMessage += `\nEmails non envoyés : ${failedEmails}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
currentBtnState.value = {
|
currentBtnState.value = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue