Buckets:
evalstate/sandbox-testing-2 / hf-mcp-server /packages /app /src /server /transport /json-rpc-errors.ts
| // json-rpc-errors.ts | |
| const JSON_RPC_ERROR_CODES = { | |
| // Standard JSON-RPC 2.0 error codes | |
| PARSE_ERROR: -32700, | |
| INVALID_REQUEST: -32600, | |
| METHOD_NOT_FOUND: -32601, | |
| INVALID_PARAMS: -32602, | |
| INTERNAL_ERROR: -32603, | |
| // Server error codes (-32000 to -32099) | |
| SERVER_ERROR: -32000, | |
| SESSION_NOT_FOUND: -32001, | |
| SERVER_SHUTTING_DOWN: -32002, | |
| SESSION_ALREADY_EXISTS: -32003, | |
| STALE_CONNECTION: -32004, | |
| AUTHENTICATION_FAILED: -32005, | |
| } as const; | |
| type JsonRpcErrorCode = (typeof JSON_RPC_ERROR_CODES)[keyof typeof JSON_RPC_ERROR_CODES]; | |
| interface JsonRpcError { | |
| jsonrpc: '2.0'; | |
| error: { | |
| code: JsonRpcErrorCode; | |
| message: string; | |
| data?: unknown; | |
| }; | |
| id: string | number | null; | |
| } | |
| /** | |
| * Create a JSON-RPC 2.0 error response | |
| */ | |
| function createJsonRpcError( | |
| code: JsonRpcErrorCode, | |
| message: string, | |
| id: string | number | null = null, | |
| data?: unknown | |
| ): JsonRpcError { | |
| const error: JsonRpcError = { | |
| jsonrpc: '2.0', | |
| error: { | |
| code, | |
| message, | |
| }, | |
| id, | |
| }; | |
| if (data !== undefined) { | |
| error.error.data = data; | |
| } | |
| return error; | |
| } | |
| /** | |
| * Safely extract JSON-RPC ID from request body | |
| */ | |
| export function extractJsonRpcId(body: unknown): string | number | null { | |
| if (body && typeof body === 'object' && 'id' in body) { | |
| const id = (body as { id: unknown }).id; | |
| if (typeof id === 'string') { | |
| return id; | |
| } | |
| if (typeof id === 'number') { | |
| return id; | |
| } | |
| if (id === null) { | |
| return null; | |
| } | |
| } | |
| return null; | |
| } | |
| /** | |
| * Common error response factories | |
| */ | |
| export const JsonRpcErrors = { | |
| internalError: (id: string | number | null = null, details?: string) => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.INTERNAL_ERROR, details || 'Internal server error', id), | |
| invalidParams: (message: string, id: string | number | null = null) => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.INVALID_PARAMS, `Invalid params: ${message}`, id), | |
| sessionNotFound: (sessionId: string, id: string | number | null = null) => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.SESSION_NOT_FOUND, 'Session not found', id, { sessionId }), | |
| serverShuttingDown: (id: string | number | null = null) => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.SERVER_SHUTTING_DOWN, 'Server is shutting down', id), | |
| sessionAlreadyExists: (sessionId: string, id: string | number | null = null) => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.SESSION_ALREADY_EXISTS, 'Session already exists', id, { sessionId }), | |
| methodNotAllowed: (id: string | number | null = null, message: string = 'Method not allowed') => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.SERVER_ERROR, message, id), | |
| methodNotFound: (id: string | number | null = null, message: string = 'Method not found') => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND, message, id), | |
| invalidRequest: (id: string | number | null = null, message: string = 'Invalid request') => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.INVALID_REQUEST, message, id), | |
| authenticationFailed: (id: string | number | null = null, message: string = 'Authentication failed') => | |
| createJsonRpcError(JSON_RPC_ERROR_CODES.AUTHENTICATION_FAILED, message, id), | |
| } as const; | |
Xet Storage Details
- Size:
- 3.09 kB
- Xet hash:
- 7435f0fe355d62c593d77952408b86a770b3d0ec972a92de70927320d48dbe74
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.