MCPcopy
hub / github.com/anomalyco/opencode / json

Function json

packages/client/src/generated/client.ts:1006–1025  ·  view source on GitHub ↗
(response: Response)

Source from the content-addressed store, hash-verified

1004}
1005
1006async function json(response: Response): Promise<unknown> {
1007 if (!isContentType(response, "application/json") && !response.headers.get("content-type")?.includes("+json")) {
1008 try {
1009 await response.body?.cancel()
1010 } catch {}
1011 throw new ClientError("UnsupportedContentType")
1012 }
1013 let text: string
1014 try {
1015 text = await response.text()
1016 } catch (cause) {
1017 throw new ClientError("Transport", { cause })
1018 }
1019 if (text === "") throw new ClientError("MalformedResponse")
1020 try {
1021 return JSON.parse(text)
1022 } catch (cause) {
1023 throw new ClientError("MalformedResponse", { cause })
1024 }
1025}
1026
1027function isContentType(response: Response, expected: string) {
1028 return response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() === expected

Callers 4

responseErrorFunction · 0.70
requestFunction · 0.70
workspace.sql.tsFile · 0.50
billing.sql.tsFile · 0.50

Calls 4

isContentTypeFunction · 0.85
getMethod · 0.65
cancelMethod · 0.65
textMethod · 0.65

Tested by

no test coverage detected