mcp-wayback-machine
Version:
MCP server and CLI tool for interacting with the Wayback Machine without API keys
42 lines (40 loc) • 1.25 kB
JavaScript
export class HttpError extends Error {
status;
response;
constructor(message, status, response) {
super(message);
this.name = "HttpError";
this.status = status;
this.response = response;
}
}
/**
* * Wrapper around fetch with timeout support and error handling
*/
export async function fetchWithTimeout(url, options = {}) {
const { timeout = 30000, ...fetchOptions } = options;
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort();
}, timeout);
try {
const response = await fetch(url, {
...fetchOptions,
signal: controller.signal,
});
clearTimeout(timeoutId);
if (!response.ok) {
const text = await response.text().catch(() => "");
throw new HttpError(`HTTP ${String(response.status)}: ${response.statusText}`, response.status, text);
}
return response;
}
catch (error) {
clearTimeout(timeoutId);
if (error instanceof Error && error.name === "AbortError") {
throw new HttpError(`Request timeout after ${String(timeout)}ms`);
}
throw error;
}
}
//# sourceMappingURL=http.js.map