Edits history of script submission #22360 for ' Send the error to discord (discord)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    type DiscordWebhook = {
      webhook_url: string;
    };
    export async function main(
      discord_webhook: DiscordWebhook,
      message: string,
      name: string,
    ) {
      const flow_id = Bun.env.WM_FLOW_JOB_ID;
      message = `Flow [${flow_id}](${Bun.env.WM_BASE_URL}/run/${flow_id}?workspace=${Bun.env.WM_WORKSPACE}) had an error:\n${name}: ${message}`;
      const response = await fetch(`${discord_webhook.webhook_url}?wait=true`, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ content: message }),
      });
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`);
      }
      return await response.json();
    }
    

    Submitted by hugo989 4 days ago