// Standard error contract
export interface RpcError {
code: string;
message: string;
details?: any;
}
// Custom error classes
export class RpcBaseError extends Error {
constructor(
public code: string,
message: string,
public details?: any
) {
super(message);
this.name = 'RpcBaseError';
}
toJSON(): RpcError {
return {
code: this.code,
message: this.message,
details: this.details
};
}
}
export class ValidationError extends RpcBaseError {
constructor(message: string, details?: any) {
super('VALIDATION_ERROR', message, details);
this.name = 'ValidationError';
}
}
export class AuthenticationError extends RpcBaseError {
constructor(message: string) {
super('AUTHENTICATION_ERROR', message);
this.name = 'AuthenticationError';
}
}
export class NotFoundError extends RpcBaseError {
constructor(message: string) {
super('NOT_FOUND_ERROR', message);
this.name = 'NotFoundError';
}
}
export class ExternalServiceError extends RpcBaseError {
constructor(message: string, details?: any) {
super('EXTERNAL_SERVICE_ERROR', message, details);
this.name = 'ExternalServiceError';
}
}
export class InternalError extends RpcBaseError {
constructor(message: string, details?: any) {
super('INTERNAL_ERROR', message, details);
this.name = 'InternalError';
}
}