UNPKG

mcp-wayback-machine

Version:

MCP server and CLI tool for interacting with the Wayback Machine without API keys

55 lines 1.63 kB
/** * HTTP utilities for making API calls to the Wayback Machine */ export class HttpError extends Error { status; response; constructor(message, status, response) { super(message); this.status = status; this.response = response; this.name = 'HttpError'; } } /** * 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 ${response.status}: ${response.statusText}`, response.status, text); } return response; } catch (error) { clearTimeout(timeoutId); if (error instanceof Error) { if (error.name === 'AbortError') { throw new HttpError(`Request timeout after ${timeout}ms`); } throw error; } throw new HttpError('Network error occurred'); } } /** * Parse JSON response with error handling */ export async function parseJsonResponse(response) { try { return await response.json(); } catch (error) { throw new HttpError('Failed to parse JSON response'); } } //# sourceMappingURL=http.js.map