(
path: string,
init: RequestInit,
schema: T,
retryOptions: { retries?: number; backoffMs?: number } = {},
)
| 29 | import { z } from "zod"; |
| 30 | |
| 31 | const requestLighthouse = async <T extends z.ZodTypeAny>( |
| 32 | path: string, |
| 33 | init: RequestInit, |
| 34 | schema: T, |
| 35 | retryOptions: { retries?: number; backoffMs?: number } = {}, |
| 36 | ): Promise<z.infer<T> | ServiceError> => { |
| 37 | const url = `${env.SOURCEBOT_LIGHTHOUSE_URL}${path}`; |
| 38 | |
| 39 | let response: Response; |
| 40 | try { |
| 41 | response = await fetchWithRetry(url, init, retryOptions) |
| 42 | } catch (error) { |
| 43 | return lighthouseUnreachable(url, error); |
| 44 | } |
| 45 | |
| 46 | return parseResponseBody(response, schema); |
| 47 | } |
| 48 | |
| 49 | const jsonPost = (body: unknown): RequestInit => ({ |
| 50 | method: 'POST', |
no test coverage detected