MCPcopy
hub / github.com/pingdotgg/uploadthing / fetchEff

Function fetchEff

packages/shared/src/effect.ts:20–55  ·  view source on GitHub ↗
(
  input: string | URL,
  init?: RequestInit,
)

Source from the content-addressed store, hash-verified

18// Only for use in the browser.
19// On the server, use `@effect/platform.HttpClient` instead.
20export const fetchEff = (
21 input: string | URL,
22 init?: RequestInit,
23): Micro.Micro<ResponseWithURL, FetchError, FetchContext> =>
24 Micro.flatMap(Micro.service(FetchContext), (fetch) => {
25 const headers = new Headers(init?.headers ?? []);
26
27 const reqInfo = {
28 url: input.toString(),
29 method: init?.method,
30 body: init?.body,
31 headers: Object.fromEntries(headers),
32 };
33
34 return Micro.tryPromise({
35 try: (signal) => fetch(input, { ...init, headers, signal }),
36 catch: (error) =>
37 new FetchError({
38 error:
39 error instanceof Error
40 ? {
41 ...error,
42 name: error.name,
43 message: error.message,
44 stack: error.stack,
45 }
46 : error,
47 input: reqInfo,
48 }),
49 }).pipe(
50 // eslint-disable-next-line no-console
51 Micro.tapError((e) => Micro.sync(() => console.error(e.input))),
52 Micro.map((res) => Object.assign(res, { requestUrl: reqInfo.url })),
53 Micro.withTrace("fetch"),
54 );
55 });
56
57export const parseResponseJson = (
58 res: ResponseWithURL,

Callers 3

uploadFileFunction · 0.90
createUTReporterFunction · 0.90
uploadFileFunction · 0.90

Calls 1

fetchFunction · 0.85

Tested by

no test coverage detected