0
Workspace or Email error handler Failure
One script reply has been approved by the moderators Verified
Created by dieriba.pro916 25 days ago Viewed 865 times
0
Submitted by dieriba.pro916 Bun
Verified 25 days ago
1
//native
2

3
export async function main(
4
  email_recipients: string[],
5
  workspace_id: string,
6
  job_id: string, // The UUID of the job that errored
7
  path: string, // The path of the script or flow that errored
8
  is_flow: boolean, // Whether the runnable is a flow
9
  error: object, // The error details
10
  started_at: string, // The start datetime of the latest job that failed
11
  trigger_path?: string, // The path of the trigger that errored in the format <trigger_type>/<trigger_path>
12
) {
13

14
  const token = process.env["WM_TOKEN"]
15
  const base_internal_url = process.env["BASE_INTERNAL_URL"]
16
  const fullUrl = `${base_internal_url}/api/w/${workspace_id}/jobs/send_email_with_instance_smtp`
17
  const body = { workspace_id, job_id, is_flow, error, started_at, runnable_path: path, trigger_path, email_recipients }
18
  try {
19
    console.log(`Sending request to ${fullUrl}`)
20
    let response = await fetch(fullUrl, {
21
      method: "POST",
22
      headers: {
23
        "Content-Type": "application/json",
24
        "Authorization": `Bearer ${token}`
25
      },
26
      body: JSON.stringify(body)
27
    })
28

29
    if (!response.ok) {
30
      throw Error(await response.text())
31
    }
32

33
    response = await response.json()
34
    console.log(`Response: ${response}`)
35
    return response
36
  } catch (error) {
37
    console.error(`Error: ${error}`)
38
  }
39
}