bnb-passport-attestation
Version:
BAS SDK - A toolkit for blockchain interaction
43 lines (42 loc) • 1.38 kB
TypeScript
import { Contract } from 'ethers';
/**
* Error type enumeration
* @typedef {'transaction' | 'contract' | 'passport' | 'mint' | 'invite'} ErrorType
*/
export type ErrorType = 'transaction' | 'contract' | 'passport' | 'mint' | 'invite';
/**
* Error code interface definition
* @interface ErrorCode
* @property {string} code - Error code
* @property {string} message - Error message
* @property {ErrorType} type - Error type
*/
export interface ErrorCode {
code: string;
message: string;
type: ErrorType;
}
/**
* Error code mapping table
* Includes transaction errors, contract errors, passport contract specific errors,
* minting errors, and invite code related errors
* @type {Record<string, ErrorCode>}
*/
export declare const ERROR_CODES: Record<string, ErrorCode>;
/**
* Parse contract error
* Checks in order: user rejection, contract error, predefined error codes, original error message
*
* @param {any} error - Error object
* @param {Contract} [contract] - ethers.js contract instance for parsing contract errors
* @returns {Promise<string>} Formatted error message
*
* @example
* try {
* await contract.someFunction();
* } catch (error) {
* const message = await parseContractError(error, contract);
* console.error(message);
* }
*/
export declare function parseContractError(error: any, contract?: Contract): Promise<string>;