/** * Consignment Verification Error * * Error thrown when RGB consignment verification fails * * @module features/gas-free/errors/ConsignmentVerificationError */ import { GasFreeError, GasFreeErrorCode } from './GasFreeError'; /** * ConsignmentVerificationError class * * Thrown when RGB consignment verification fails. */ export class ConsignmentVerificationError extends GasFreeError { /** Verification errors */ public readonly verificationErrors?: string[]; /** Transaction ID (if available) */ public readonly txid?: string; /** * Create a ConsignmentVerificationError * * @param message - Error message * @param verificationErrors - Array of verification error messages * @param txid - Transaction ID (if available) * @param originalError - Original error */ constructor( message: string, verificationErrors?: string[], txid?: string, originalError?: Error ) { super( message, GasFreeErrorCode.CONSIGNMENT_VERIFICATION_FAILED, originalError, { verificationErrors, txid, } ); this.name = 'ConsignmentVerificationError'; this.verificationErrors = verificationErrors; this.txid = txid; // Maintains proper stack trace for where our error was thrown (only available on V8) if (Error.captureStackTrace) { Error.captureStackTrace(this, ConsignmentVerificationError); } } /** * Create error for verification failure */ static verificationFailed( errors: string[], txid?: string ): ConsignmentVerificationError { return new ConsignmentVerificationError( `Consignment verification failed:\n- ${errors.join('\n- ')}`, errors, txid ); } /** * Create error for invalid consignment */ static invalidConsignment( reason: string, txid?: string ): ConsignmentVerificationError { return new ConsignmentVerificationError( `Invalid consignment: ${reason}`, [reason], txid ); } /** * Create error for missing consignment */ static missingConsignment(txid: string): ConsignmentVerificationError { return new ConsignmentVerificationError( `Consignment not found for transaction ${txid}`, ['Consignment not found'], txid ); } /** * Convert error to JSON */ toJSON(): Record { return { ...super.toJSON(), verificationErrors: this.verificationErrors, txid: this.txid, }; } }