Skip to content

Commit 4e749db

Browse files
Add isJSONRPCError method
1 parent 8215651 commit 4e749db

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/shared/protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
CancelledNotificationSchema,
44
ClientCapabilities,
55
ErrorCode,
6+
isJSONRPCError,
67
isJSONRPCRequest,
78
isJSONRPCResponse,
89
isJSONRPCNotification,
@@ -274,7 +275,7 @@ export abstract class Protocol<
274275
};
275276

276277
this._transport.onmessage = (message) => {
277-
if (isJSONRPCResponse(message)) {
278+
if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
278279
this._onresponse(message);
279280
} else if (isJSONRPCRequest(message)) {
280281
this._onrequest(message);

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ export const JSONRPCErrorSchema = z
150150
})
151151
.strict();
152152

153+
export const isJSONRPCError = (value: unknown): value is JSONRPCError =>
154+
JSONRPCErrorSchema.safeParse(value).success;
155+
153156
export const JSONRPCMessageSchema = z.union([
154157
JSONRPCRequestSchema,
155158
JSONRPCNotificationSchema,

0 commit comments

Comments
 (0)