Add isJSONRPCError method
This commit is contained in:
parent
8215651552
commit
4e749dba4d
2 changed files with 5 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import {
|
|||
CancelledNotificationSchema,
|
||||
ClientCapabilities,
|
||||
ErrorCode,
|
||||
isJSONRPCError,
|
||||
isJSONRPCRequest,
|
||||
isJSONRPCResponse,
|
||||
isJSONRPCNotification,
|
||||
|
|
@ -274,7 +275,7 @@ export abstract class Protocol<
|
|||
};
|
||||
|
||||
this._transport.onmessage = (message) => {
|
||||
if (isJSONRPCResponse(message)) {
|
||||
if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
|
||||
this._onresponse(message);
|
||||
} else if (isJSONRPCRequest(message)) {
|
||||
this._onrequest(message);
|
||||
|
|
|
|||
|
|
@ -150,6 +150,9 @@ export const JSONRPCErrorSchema = z
|
|||
})
|
||||
.strict();
|
||||
|
||||
export const isJSONRPCError = (value: unknown): value is JSONRPCError =>
|
||||
JSONRPCErrorSchema.safeParse(value).success;
|
||||
|
||||
export const JSONRPCMessageSchema = z.union([
|
||||
JSONRPCRequestSchema,
|
||||
JSONRPCNotificationSchema,
|
||||
|
|
|
|||
Loading…
Reference in a new issue