Edits history of script submission #13993 for ' Workspace or Email error handler (windmill)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    export async function main(
      email_recipients: string[],
      workspace_id: string,
      job_id: string, // The UUID of the job that errored
      path: string, // The path of the script or flow that errored
      is_flow: boolean, // Whether the runnable is a flow
      error: object, // The error details
      started_at: string, // The start datetime of the latest job that failed
      trigger_path?: string, // The path of the trigger that errored in the format <trigger_type>/<trigger_path>
    ) {
    
      const token = process.env["WM_TOKEN"]
      const base_internal_url = process.env["BASE_INTERNAL_URL"]
      const fullUrl = `${base_internal_url}/api/w/${workspace_id}/jobs/send_email_with_instance_smtp`
      const body = { workspace_id, job_id, is_flow, error, started_at, runnable_path: path, trigger_path, email_recipients }
      try {
        console.log(`Sending request to ${fullUrl}`)
        let response = await fetch(fullUrl, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${token}`
          },
          body: JSON.stringify(body)
        })
    
        if (!response.ok) {
          throw Error(await response.text())
        }
    
        response = await response.json()
        console.log(`Response: ${response}`)
        return response
      } catch (error) {
        console.error(`Error: ${error}`)
      }
    }

    Submitted by dieriba.pro916 307 days ago