Set default error or recoevery handler

Script windmill Verified

by hugo697 ยท 3/6/2024

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * Set default error or recoevery handler
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  body: {
8
    handler_type: "error" | "recovery";
9
    override_existing: boolean;
10
    path?: string;
11
    extra_args?: { [k: string]: unknown };
12
    number_of_occurence?: number;
13
    number_of_occurence_exact?: boolean;
14
    workspace_handler_muted?: boolean;
15
    [k: string]: unknown;
16
  }
17
) {
18
  const url = new URL(
19
    `${BASE_URL}/api/w/${workspace}/schedules/setdefaulthandler`
20
  );
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + WM_TOKEN,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.text();
35
}
36