feat: improve discord webhook configuration flexibility and add error logging for failed requests
This commit is contained in:
parent
0c1c566b3d
commit
d196a73d85
1 changed files with 14 additions and 4 deletions
|
|
@ -68,11 +68,16 @@ async function sendDiscordNotification(payload: {
|
||||||
tags: string[];
|
tags: string[];
|
||||||
imageUrl?: string;
|
imageUrl?: string;
|
||||||
}) {
|
}) {
|
||||||
const webhookUrl = config.discord.webhook;
|
const webhookUrl = (config as any)?.webhook?.discord_webhook_uri
|
||||||
if (!webhookUrl) return;
|
?? (config as any)?.discord?.webhook;
|
||||||
|
|
||||||
|
if (!webhookUrl || typeof webhookUrl !== "string") {
|
||||||
|
console.warn("[Discord Webhook] missing webhook URL in config.toml (expected [webhook].discord_webhook_uri)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetch(webhookUrl, {
|
const response = await fetch(webhookUrl, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
@ -86,6 +91,11 @@ async function sendDiscordNotification(payload: {
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text().catch(() => "");
|
||||||
|
console.error(`[Discord Webhook] failed status=${response.status} body=${errorText}`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[Discord Webhook Error]", error);
|
console.error("[Discord Webhook Error]", error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue