@xtr-dev/zod-rpc
Version:
Simple, type-safe RPC library with Zod validation and automatic TypeScript inference
95 lines • 2.53 kB
TypeScript
/**
* Base class for all RPC-related errors.
* Provides structured error information with error codes and trace IDs for debugging.
*
* @example
* ```typescript
* try {
* await client.user.get({ userId: 'invalid' });
* } catch (error) {
* if (error instanceof RPCError) {
* console.log('RPC Error:', error.code, error.message, error.traceId);
* }
* }
* ```
*
* @group Error Classes
*/
export declare class RPCError extends Error {
code: string;
traceId?: string | undefined;
constructor(code: string, message: string, traceId?: string | undefined);
toJSON(): Record<string, unknown>;
}
/**
* Error thrown when input or output validation fails.
* Occurs when data doesn't match the expected Zod schemas.
*
* @example
* ```typescript
* // This would throw ValidationError if userId is not a string
* await client.user.get({ userId: 123 });
* ```
*
* @group Error Classes
*/
export declare class ValidationError extends RPCError {
constructor(message: string, traceId?: string);
}
/**
* Error thrown when transport layer communication fails.
* Includes WebSocket connection errors, HTTP failures, etc.
*
* @example
* ```typescript
* try {
* await client.user.get({ userId: '123' });
* } catch (error) {
* if (error instanceof TransportError) {
* console.log('Connection failed:', error.message);
* }
* }
* ```
*
* @group Error Classes
*/
export declare class TransportError extends RPCError {
constructor(message: string, traceId?: string);
}
/**
* Error thrown when attempting to call a method that doesn't exist.
* Usually indicates the server hasn't implemented the requested method.
*
* @example
* ```typescript
* // Throws if 'nonexistent' method isn't implemented
* await client.user.nonexistent({ data: 'test' });
* ```
*
* @group Error Classes
*/
export declare class MethodNotFoundError extends RPCError {
constructor(methodId: string, traceId?: string);
}
/**
* Error thrown when an RPC call exceeds its timeout duration.
* Can be configured per-call or use the default timeout.
*
* @example
* ```typescript
* try {
* // This call has a 1 second timeout
* await client.user.get({ userId: '123' }, { timeout: 1000 });
* } catch (error) {
* if (error instanceof TimeoutError) {
* console.log('Call timed out');
* }
* }
* ```
*
* @group Error Classes
*/
export declare class TimeoutError extends RPCError {
constructor(message: string, traceId?: string);
}
//# sourceMappingURL=errors.d.ts.map