/** * A small, library-free Chain of Responsibility to normalize diverse MLS/core-crypto/backend * errors into a closed {@link DomainMlsError} union. This module is side-effect free and only * classifies errors; recovery actions are implemented by a separate orchestrator. */ import { SUBCONVERSATION_ID } from '@wireapp/api-client/lib/conversation'; import { QualifiedId } from '@wireapp/api-client/lib/user'; import { MlsErrorType } from '@wireapp/core-crypto'; /** * Domain error taxonomy used by policies and orchestrator. * * These are intentionally decoupled from concrete error classes to keep the orchestrator stable. */ export type DomainMlsErrorType = MlsErrorType | 'KeyMaterialUpdateFailure' | 'GroupOutOfSync' | 'GroupNotEstablished'; /** * Normalized error shape produced by the mapper. */ export type DomainMlsError = { /** The domain classification. */ type: DomainMlsErrorType; /** Optional human-friendly message for logging only. */ message?: string; /** The original error value, preserved for debugging. */ cause?: unknown; /** Lightweight, structured context to inform recovery. */ context?: { /** Conversation qualified id if known. */ qualifiedConversationId?: QualifiedId; /** MLS group id (base64) if available. */ groupId?: string; /** Expected/observed epoch number if relevant. */ epoch?: number | bigint; /** Users reported as missing by the backend or MLS layer. */ missingUsers?: QualifiedId[]; /** Subconversation context (e.g. conference). */ subconvId?: SUBCONVERSATION_ID; /** HTTP status when the source error came from the backend. */ httpStatus?: number; }; }; /** * Optional context supplied by the caller to improve mapping precision. */ export type ErrorContextInput = { qualifiedConversationId?: QualifiedId; groupId?: string; subconvId?: SUBCONVERSATION_ID; }; /** One handler in the chain. Must be side-effect free. */ export interface ErrorHandler { /** True if this handler can map the provided error given optional context. */ canHandle(error: unknown, context?: ErrorContextInput): boolean; /** Return a mapped error or undefined to defer to later handlers. */ map(error: unknown, context?: ErrorContextInput): DomainMlsError; } /** Public mapper interface returning a normalized {@link DomainMlsError}. */ export interface MlsErrorMapper { map(error: unknown, context?: ErrorContextInput): DomainMlsError; } /** * Deterministic chain execution * * The first handler that both * canHandle and returns a non-undefined mapping wins. If none map, an Unknown error is returned. */ export declare class ChainedMlsErrorMapper implements MlsErrorMapper { private readonly handlers; constructor(handlers: ErrorHandler[]); map(error: unknown, context?: ErrorContextInput): DomainMlsError; } /** * Factory for the default mapper chain used by the orchestrator. * * Order matters: earlier handlers have higher precedence. The selection reflects * the most common recovery decisions needed by the orchestrator. */ export declare function createDefaultMlsErrorMapper(): MlsErrorMapper; //# sourceMappingURL=MlsErrorMapper.d.ts.map