MCPcopy
hub / github.com/Effect-TS/effect / fromResponseError

Method fromResponseError

packages/ai/ai/src/AiError.ts:387–417  ·  view source on GitHub ↗

* Creates an HttpResponseError from a platform HttpClientError.ResponseError. * * @example * ```ts * import { AiError } from "@effect/ai" * import { Headers, HttpClientError } from "@effect/platform" * import { Option } from "effect" * * declare const platformError: HttpClien

({ error, ...params }: {
    readonly module: string
    readonly method: string
    readonly error: HttpClientError.ResponseError
  })

Source from the content-addressed store, hash-verified

385 * @category Constructors
386 */
387 static fromResponseError({ error, ...params }: {
388 readonly module: string
389 readonly method: string
390 readonly error: HttpClientError.ResponseError
391 }): Effect.Effect<never, HttpResponseError> {
392 let body: Effect.Effect<unknown, HttpClientError.ResponseError> = Effect.void
393 const contentType = error.response.headers["content-type"] ?? ""
394 if (contentType.includes("application/json")) {
395 body = error.response.json
396 } else if (contentType.includes("text/") || contentType.includes("urlencoded")) {
397 body = error.response.text
398 }
399 return Effect.flatMap(Effect.merge(body), (body) =>
400 new HttpResponseError({
401 ...params,
402 description: error.description,
403 reason: error.reason,
404 request: {
405 hash: error.request.hash,
406 headers: Inspectable.redact(error.request.headers) as any,
407 method: error.request.method,
408 url: error.request.url,
409 urlParams: error.request.urlParams
410 },
411 response: {
412 headers: Inspectable.redact(error.response.headers) as any,
413 status: error.response.status
414 },
415 body: Inspectable.format(body)
416 }, { disableValidation: true }))
417 }
418
419 get message(): string {
420 const methodUrlStatus = `${this.response.status} ${this.request.method} ${this.request.url}`

Callers 11

streamRequestFunction · 0.80
AnthropicClient.tsFile · 0.80
makeFunction · 0.80
streamRequestFunction · 0.80
streamRequestFunction · 0.80
makeFunction · 0.80
streamRequestFunction · 0.80
createResponseFunction · 0.80
createEmbeddingFunction · 0.80
streamRequestFunction · 0.80

Calls 1

mergeMethod · 0.80

Tested by

no test coverage detected