Skip to content
Myr

legacy.ts

This file

Path

packages/kit/src/legacy.ts

28 lines · 799 bytes · TypeScript

Last changed by

landed by oscabriel6182530

History of this file

Take it

landed by oscabriel6182530

lines 1–28
1import { fetchTransport, isSuccess } from "./transport.ts";
2import type { Transport } from "./transport.ts";34// How many requests went out through `legacyFetch`, for the debug page.5let requestsSent = 0;67/** How many requests `legacyFetch` has sent since the process started. */8export const legacyRequestsSent = () => requestsSent;910/**11 * The first HTTP helper, from before `http.get`: it returns the body as12 * text and throws on any status that isn't a success. New code uses13 * `http.get`.14 */15export const legacyFetch = async (16 url: string,17 transport: Transport = fetchTransport18): Promise<string> => {19 requestsSent += 1;2021 const reply = await transport(url);2223 if (!isSuccess(reply.status)) {24 throw new Error(`GET ${url} answered ${reply.status}`);25 }2627 return reply.text;28};