diff --git a/deno.jsonc b/deno.jsonc index ca1bebf..52c68ef 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -11,7 +11,7 @@ "imports": { "COLOR": "https://esm.sh/color@4.2.3", "COLORNAMESPACELISTCOMMUNITY": "https://esm.sh/color-name-list@11.2.0/dist/colornames.esm.js", - "EXFETCH/": "https://raw.githubusercontent.com/hugoalh/exfetch-es/v0.5.1/", + "EXFETCH/": "https://raw.githubusercontent.com/hugoalh/exfetch-es/v0.6.0/", "FS/": "https://raw.githubusercontent.com/hugoalh/fs-es/v0.3.1/", "GHACTIONS/": "https://raw.githubusercontent.com/hugoalh/github-actions-core-es/v0.4.3/", "ISJSON/": "https://raw.githubusercontent.com/hugoalh/is-json-es/v1.0.4/", diff --git a/mod.ts b/mod.ts index fdbc32b..47e573a 100644 --- a/mod.ts +++ b/mod.ts @@ -1,6 +1,6 @@ import { - ExFetch, - userAgentDefault + exFetch, + type ExFetchEventRetryPayload } from "EXFETCH/mod.ts"; import { addSecretMask, @@ -32,11 +32,9 @@ import { resolveUsername } from "./_payload.ts"; console.log("Initialize."); -const exfetch: ExFetch = new ExFetch({ - userAgent: `${userAgentDefault} SendDiscordWebhook.GitHubAction/7.0.4` -}); const splitterNewLine = /\r?\n/g; const splitterCommonDelimiter = /,|\r?\n/g; +const userAgent = `SendDiscordWebhook.GitHubAction/7.0.4`; writeDebug(`Environment Variables:\n\t${Object.entries(Deno.env.toObject()).map(([key, value]: [string, string]): string => { return `${key} = ${value}`; }).join("\n\t")}`); @@ -161,11 +159,28 @@ try { return requestPayloadStringify; })(); console.log(`Post network request to Discord.`); - const response: Response = await exfetch.fetch(`https://discord.com/api/webhooks/${key}${(discordWebhookUrlParameters.size > 0) ? `?${discordWebhookUrlParameters.toString()}` : ""}`, { + const response: Response = await exFetch(`https://discord.com/api/webhooks/${key}${(discordWebhookUrlParameters.size > 0) ? `?${discordWebhookUrlParameters.toString()}` : ""}`, { body: requestBody, headers: requestHeaders, method: "POST", redirect: "follow" + }, { + retry: { + onRetry({ + countCurrent, + countMaximum, + statusCode, + statusText, + timeWait + }: ExFetchEventRetryPayload): void { + console.log(`Last network request failed with status \`${statusCode} ${statusText}. Retry #${countCurrent}/${countMaximum} after ${timeWait / 1000} seconds\`.`); + }, + timeWait: { + maximum: 120000, + minimum: 10000 + } + }, + userAgent }).catch((reason: Error): never => { throw new Error(`Unexpected web request issue: ${reason?.message ?? reason}`); });