/** * ECPay 支付錯誤基礎類別 * * 所有 ECPay SDK 相關錯誤的基礎類別,提供統一的錯誤處理機制。 * * @example * ```typescript * try { * await client.query(payment) * } catch (error) { * if (error instanceof PaymentError) { * console.log(error.code) // 'REQUIRED', 'INVALID', etc. * console.log(error.field) // 'MerchantID', etc. * } * } * ``` */ export declare class PaymentError extends Error { /** * 錯誤代碼 */ readonly code: string; /** * 相關欄位名稱(如果有的話) */ readonly field?: string; constructor(message: string, code?: string, field?: string); /** * 建立必填欄位錯誤 * * @param field - 欄位名稱 * @returns PaymentError 實例 */ static required(field: string): PaymentError; /** * 建立欄位長度過長錯誤 * * @param field - 欄位名稱 * @param maxLength - 最大長度限制 * @returns PaymentError 實例 */ static tooLong(field: string, maxLength: number): PaymentError; /** * 建立欄位值無效錯誤 * * @param field - 欄位名稱 * @param reason - 無效原因說明 * @returns PaymentError 實例 */ static invalid(field: string, reason: string): PaymentError; /** * 建立 CheckMacValue 驗證失敗錯誤 * * @returns PaymentError 實例 */ static checkMacValueFailed(): PaymentError; /** * 建立 HTTP 請求錯誤 * * @param status - HTTP 狀態碼 * @param statusText - HTTP 狀態文字 * @returns PaymentError 實例 */ static httpError(status: number, statusText: string): PaymentError; /** * 建立請求逾時錯誤 * * @param timeout - 逾時時間(毫秒) * @param url - 請求的 URL(選填) * @returns PaymentError 實例 */ static timeout(timeout: number, url?: string): PaymentError; /** * 建立網路錯誤 * * @param reason - 錯誤原因 * @returns PaymentError 實例 */ static networkError(reason: string): PaymentError; /** * 將錯誤轉換為 JSON 可序列化物件 * * @returns 包含所有錯誤屬性的物件 */ toJSON(): Record; }