MCPcopy Create free account
hub / github.com/Effect-TS/effect / reasonFromHttpStatus

Function reasonFromHttpStatus

packages/effect/src/unstable/ai/AiError.ts:1579–1607  ·  view source on GitHub ↗
(params: {
  readonly status: number
  readonly body?: unknown
  readonly http?: typeof HttpContext.Type
  readonly metadata?: typeof ProviderMetadata.Type
  readonly description?: string | undefined
})

Source from the content-addressed store, hash-verified

1577 * @since 4.0.0
1578 */
1579export const reasonFromHttpStatus = (params: {
1580 readonly status: number
1581 readonly body?: unknown
1582 readonly http?: typeof HttpContext.Type
1583 readonly metadata?: typeof ProviderMetadata.Type
1584 readonly description?: string | undefined
1585}): AiErrorReason => {
1586 const { status, http, metadata, description } = params
1587 const common = {
1588 http,
1589 ...(metadata ? { metadata } : undefined),
1590 ...(description ? { description } : undefined)
1591 }
1592 switch (status) {
1593 case 400:
1594 return new InvalidRequestError(common)
1595 case 401:
1596 return new AuthenticationError({ kind: "InvalidKey", ...common })
1597 case 403:
1598 return new AuthenticationError({ kind: "InsufficientPermissions", ...common })
1599 case 429:
1600 return new RateLimitError(common)
1601 default:
1602 if (status >= 500) {
1603 return new InternalProviderError({ description: "Server error", ...common })
1604 }
1605 return new UnknownError(common)
1606 }
1607}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected