0

Echo

by
Published Oct 17, 2025

Public Echo endpoint.

Script segment Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Segment = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Echo
8
 * Public Echo endpoint.
9
 */
10
export async function main(
11
  auth: Segment,
12
  message: string | undefined,
13
  delay: string | undefined,
14
  triggerError: string | undefined,
15
  triggerMultipleErrors: string | undefined,
16
  triggerUnexpectedError: string | undefined,
17
  statusCode: string | undefined,
18
) {
19
  const url = new URL(`${auth.baseUrl}/echo`);
20
  for (const [k, v] of [
21
    ["message", message],
22
    ["delay", delay],
23
    ["triggerError", triggerError],
24
    ["triggerMultipleErrors", triggerMultipleErrors],
25
    ["triggerUnexpectedError", triggerUnexpectedError],
26
    ["statusCode", statusCode],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45