Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-years-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/rpc": patch
---

Fix JsonRpc client message handling
3 changes: 2 additions & 1 deletion packages/rpc/src/RpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,8 @@ export const makeProtocolHttp = (client: HttpClient.HttpClient): Effect.Effect<

if (isJson) {
return client.post("", { body }).pipe(
Effect.flatMap((r) => r.json),
Effect.flatMap((r) => r.text),
Effect.map((text) => parser.decode(text)),
Effect.mapError((cause) =>
new RpcClientError({
reason: "Protocol",
Expand Down
8 changes: 7 additions & 1 deletion packages/rpc/src/RpcSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ export const json: RpcSerialization["Type"] = RpcSerialization.of({
unsafeMake: () => {
const decoder = new TextDecoder()
return {
decode: (bytes) => [JSON.parse(typeof bytes === "string" ? bytes : decoder.decode(bytes))],
decode: (bytes) => {
const decoded = JSON.parse(typeof bytes === "string" ? bytes : decoder.decode(bytes))
if (Array.isArray(decoded)) {
return decoded
}
return [decoded]
},
encode: (response) => JSON.stringify(response)
}
}
Expand Down