Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions fetch-timeout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export function getDescription() {
return {
description: "Fetch With Custom Timeout",
input: [
{
id: "endpoint",
displayName: "Endpoint",
description: "URL of the endpoint to fetch data from.",
type: "Connector",
required: true,
},
{
id: "abortRequestTimeoutInMs",
displayName: "Abort Request Timeout in milliseconds",
description: "Abort Request Timeout in milliseconds.",
type: "Number",
required: true,
},
],
output: [],
} as const satisfies ScriptDescription;
}

export async function execute(context: Context): Promise<Output> {
const endpoint = context.parameters.endpoint as string;
const abortRequestTimeoutInMs = context.parameters.abortRequestTimeoutInMs as number;

const abortController = new AbortController();
const options = { signal: abortController.signal };

setTimeout(() => {
abortController.abort();
console.log("Abort called");
}, abortRequestTimeoutInMs);

const response = await fetch(endpoint, options);
const responseData = await response.text();
console.debug(responseData);
}
8 changes: 8 additions & 0 deletions fetch-timeout/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "fetch-with-custom-timeout",
"displayName": "Fetch With Custom Timeout",
"description": "Provides an example of a fetch with custom timeout. Requires a Web endpoint type connector. WARNING: you have to either read the response body or close the connection because of the limitation of 6 outbound connections.",
"fromVersion": "23.08",
"toVersion": null,
"private": true
}