import { AnyRouter , inferRouterError , Maybe } from '@trpc/server' ; import { TRPCErrorResponse } from '@trpc/server/rpc' ; export interface TRPCClientErrorLike < TRouter extends AnyRouter > { readonly message : string ; readonly shape : Maybe < inferRouterError < TRouter > > ; readonly data : Maybe < inferRouterError < TRouter > [ 'data' ] > ; } export class TRPCClientError < TRouter extends AnyRouter > extends Error implements TRPCClientErrorLike < TRouter > { deprecated public readonly originalError ; public readonly cause ; public readonly shape : Maybe < inferRouterError < TRouter > > ; public readonly data : Maybe < inferRouterError < TRouter > [ 'data' ] > ; /**
     * Fatal error - expect no more results after this error
     * Used for when WebSockets disconnect prematurely.
     */ public readonly isDone : boolean ; constructor ( message , opts ) { const cause = opts . cause ?? opts . originalError ; super ( message , { cause } ) ; this . isDone = opts . isDone ?? false ; this . cause = this . originalError = cause ; this . shape = opts . result ?. error ; this . data = opts . result ?. error . data ; this . name = 'TRPCClientError' ; Object . setPrototypeOf ( this , TRPCClientError . prototype ) ; } public static from < TRouter extends AnyRouter > ( result , opts = { } ) { if ( ! ( result instanceof Error ) ) { return new TRPCClientError < TRouter > ( ( result . error as any ) . message ?? '' , { ... opts , cause : null , result : result } ) ; } if ( result . name === 'TRPCClientError' ) { return result as TRPCClientError < any > ; } return new TRPCClientError < TRouter > ( result . message , { ... opts , cause : result , result : null } ) ; } }