summaryrefslogtreecommitdiffhomepage
path: root/packages/sdk
diff options
context:
space:
mode:
authorKit Langton <[email protected]>2026-05-03 09:17:06 -0400
committerGitHub <[email protected]>2026-05-03 13:17:06 +0000
commit379600b5ab9ed46043d1674e7fb7c3dbcb9bd4ba (patch)
treeb69e91e9649f53a2a780c86c12c994e44d43f2ed /packages/sdk
parent7a503de606888939a64776c512ca4588267bbd8d (diff)
downloadopencode-379600b5ab9ed46043d1674e7fb7c3dbcb9bd4ba.tar.gz
opencode-379600b5ab9ed46043d1674e7fb7c3dbcb9bd4ba.zip
fix(sdk+cli): surface real errors instead of bare {} when server returns empty body (#25592)
Diffstat (limited to 'packages/sdk')
-rw-r--r--packages/sdk/js/src/v2/client.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/packages/sdk/js/src/v2/client.ts b/packages/sdk/js/src/v2/client.ts
index 2d71d8446..8b49e7f10 100644
--- a/packages/sdk/js/src/v2/client.ts
+++ b/packages/sdk/js/src/v2/client.ts
@@ -84,5 +84,24 @@ export function createOpencodeClient(config?: Config & { directory?: string; exp
return response
})
+ // The generated client falls back to throwing a literal `{}` when the server
+ // responds with an empty / unparseable error body, which surfaces as a bare
+ // `{}` in TUI / CLI error output. Wrap ONLY that case in a real Error so
+ // downstream formatters get a useful message — but pass through any parsed
+ // JSON error body unchanged so existing consumers can still inspect fields.
+ client.interceptors.error.use((error, response, request) => {
+ const isEmpty =
+ error === undefined ||
+ error === null ||
+ error === "" ||
+ (typeof error === "object" && !(error instanceof Error) && Object.keys(error).length === 0)
+ if (!isEmpty) return error
+ const method = request?.method ?? "?"
+ const url = request?.url ?? "?"
+ if (!response) return new Error(`opencode server ${method} ${url}: network error (no response)`)
+ const status = response.status
+ const statusText = response.statusText ? " " + response.statusText : ""
+ return new Error(`opencode server ${method} ${url} → ${status}${statusText}: (empty response body)`)
+ })
return new OpencodeClient({ client })
}