MCPcopy
hub / github.com/anomalyco/opencode / toHttpError

Function toHttpError

packages/llm/src/route/executor.ts:307–343  ·  view source on GitHub ↗
(redactedNames: ReadonlyArray<string | RegExp>)

Source from the content-addressed store, hash-verified

305 })
306
307const toHttpError = (redactedNames: ReadonlyArray<string | RegExp>) => (error: unknown) => {
308 const transportError = (input: {
309 readonly message: string
310 readonly kind?: string | undefined
311 readonly request?: HttpClientRequest.HttpClientRequest | undefined
312 }) =>
313 new LLMError({
314 module: "RequestExecutor",
315 method: "execute",
316 reason: new TransportReason({
317 message: input.message,
318 kind: input.kind,
319 url: input.request ? redactUrl(input.request.url) : undefined,
320 http: input.request ? new HttpContext({ request: requestDetails(input.request, redactedNames) }) : undefined,
321 }),
322 })
323
324 if (Cause.isTimeoutError(error)) {
325 return transportError({ message: error.message, kind: "Timeout" })
326 }
327 if (!HttpClientError.isHttpClientError(error)) {
328 return transportError({ message: "HTTP transport failed" })
329 }
330 const request = "request" in error ? error.request : undefined
331 if (error.reason._tag === "TransportError") {
332 return transportError({
333 message: error.reason.description ?? "HTTP transport failed",
334 kind: error.reason._tag,
335 request,
336 })
337 }
338 return transportError({
339 message: `HTTP transport failed: ${error.reason._tag}`,
340 kind: error.reason._tag,
341 request,
342 })
343}
344
345const retryDelay = (error: LLMError, attempt: number) => {
346 if (error.retryAfterMs !== undefined) return Effect.succeed(Math.min(error.retryAfterMs, MAX_DELAY_MS))

Callers 1

executeOnceFunction · 0.85

Calls 1

transportErrorFunction · 0.70

Tested by

no test coverage detected