Ajoute le detail des erreurs Postal

This commit is contained in:
2026-07-20 04:57:09 +02:00
parent a3a136c65d
commit 3510289bdb
5 changed files with 1562 additions and 5 deletions
+10 -2
View File
@@ -26,9 +26,17 @@ function createPostalClient(options) {
html_body: input.htmlBody
})
});
const payload = await response.json().catch(() => null);
const rawBody = await response.text().catch(() => "");
const payload = rawBody.length > 0 ? (() => {
try {
return JSON.parse(rawBody);
} catch {
return null;
}
})() ?? null : null;
if (!response.ok || payload?.status !== "success") {
throw new Error(`postal_send_failed:${response.status}`);
const details = payload?.error?.trim() || payload?.message?.trim() || rawBody.trim().slice(0, 500) || "no_response_body";
throw new Error(`postal_send_failed:${response.status}:${details}`);
}
}
};