refactor(codemode): inline OpenAPI error summary

This commit is contained in:
Aiden Cline
2026-07-03 16:22:48 -05:00
parent d8e3b692c0
commit 04c4e90e61
@@ -69,10 +69,15 @@ export const invoke = (plan: Plan, input: unknown): Effect.Effect<unknown, unkno
const text = yield* response.text.pipe(Effect.catch(() => Effect.succeed("")))
const parsed = text === "" ? null : Option.getOrElse(decodeJson(text), () => text)
if (response.status < 200 || response.status >= 300) {
const rendered = typeof parsed === "string" ? parsed : (JSON.stringify(parsed) ?? "")
const summary =
rendered === "" || rendered === "null"
? "no response body"
: rendered.length > maxErrorBodyChars
? `${rendered.slice(0, maxErrorBodyChars)}...`
: rendered
return yield* Effect.fail(
toolError(
`${plan.operation.method} ${plan.operation.path} failed with HTTP ${response.status}: ${summarizeBody(parsed)}`,
),
toolError(`${plan.operation.method} ${plan.operation.path} failed with HTTP ${response.status}: ${summary}`),
)
}
return parsed
@@ -150,12 +155,6 @@ const applyCredentials = (credentials: ReadonlyArray<readonly [SecurityScheme, C
return { headers, query, cookies }
}
const summarizeBody = (body: unknown): string => {
const rendered = typeof body === "string" ? body : (JSON.stringify(body) ?? "")
if (rendered === "" || rendered === "null") return "no response body"
return rendered.length > maxErrorBodyChars ? `${rendered.slice(0, maxErrorBodyChars)}...` : rendered
}
const renderPrimitive = (value: unknown): string =>
typeof value === "object" && value !== null ? JSON.stringify(value) : String(value)