MCPcopy Index your code
hub / github.com/anomalyco/opencode / parseStreamError

Function parseStreamError

packages/opencode/src/provider/error.ts:102–147  ·  view source on GitHub ↗
(input: unknown)

Source from the content-addressed store, hash-verified

100 }
101
102export function parseStreamError(input: unknown): ParsedStreamError | undefined {
103 const raw = json(input)
104 const body = typeof raw?.message === "string" ? (json(raw.message) ?? raw) : raw
105 if (!body) return
106
107 const responseBody = JSON.stringify(body)
108 if (body.type !== "error") return
109
110 switch (body?.error?.code) {
111 case "context_length_exceeded":
112 return {
113 type: "context_overflow",
114 message: "Input exceeds context window of this model",
115 responseBody,
116 }
117 case "insufficient_quota":
118 return {
119 type: "api_error",
120 message: "Quota exceeded. Check your plan and billing details.",
121 isRetryable: false,
122 responseBody,
123 }
124 case "usage_not_included":
125 return {
126 type: "api_error",
127 message: "To use Codex with your ChatGPT plan, upgrade to Plus: https://chatgpt.com/explore/plus.",
128 isRetryable: false,
129 responseBody,
130 }
131 case "invalid_prompt":
132 return {
133 type: "api_error",
134 message: typeof body?.error?.message === "string" ? body?.error?.message : "Invalid prompt.",
135 isRetryable: false,
136 responseBody,
137 }
138 case "server_is_overloaded":
139 case "server_error":
140 return {
141 type: "api_error",
142 message: typeof body?.error?.message === "string" ? body?.error?.message : "Server error.",
143 isRetryable: true,
144 responseBody,
145 }
146 }
147}
148
149export type ParsedAPICallError =
150 | {

Callers

nothing calls this directly

Calls 1

jsonFunction · 0.70

Tested by

no test coverage detected