fix: surface failures of the create button

Pierre reported the button doing nothing. The click handler dropped the
async promise, so any failure became an unhandled rejection: no tab, no
message, nothing to diagnose from — whatever the underlying cause.

T1 deliberately shipped no error UI, but the field showed that choice
makes the anomaly both invisible and undiagnosable. The failure is now
caught, logged, and named on screen, and the advice to reload covers the
orphaned page case (extension reloaded while the list stayed open).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Pierre Martin
2026-07-17 11:55:23 +02:00
co-authored by Claude Opus 4.8
parent 596b5e22fd
commit 08a8cc83d3
+22 -1
View File
@@ -71,7 +71,13 @@ function rendreEvenement(evenement) {
creer.type = "button";
creer.className = "evenement-creer";
creer.textContent = "Créer sur le site mairie";
creer.addEventListener("click", () => creerSurSiteMairie(evenement));
creer.addEventListener("click", async () => {
try {
await creerSurSiteMairie(evenement);
} catch (erreur) {
rendreEchecCreation(erreur);
}
});
item.append(infos, creer);
return item;
@@ -84,6 +90,21 @@ async function creerSurSiteMairie(evenement) {
await browser.tabs.create({ url: URL_FORMULAIRE_MAIRIE });
}
// Sans ce retour, la promesse du clic échouait en silence : le bouton paraissait
// mort et la panne était indiagnosticable, y compris pour nous. Le détail
// technique est affiché volontairement — c'est ce qui permet de nommer la cause
// sans ouvrir la console. Le F5 couvre le cas de la page orpheline (extension
// rechargée dans about:debugging alors que la liste restait ouverte).
function rendreEchecCreation(erreur) {
console.error("Échec de l'ouverture du formulaire mairie", erreur);
etat.replaceChildren();
const message = document.createElement("p");
message.className = "etat-erreur";
message.textContent = `Impossible d'ouvrir le formulaire mairie : ${erreur.message}. Recharge la page (F5), puis réessaie.`;
etat.append(message);
}
function rendreErreur(typeErreur) {
etat.replaceChildren();