UNPKG

@taquito/core

Version:

Classes, interfaces, and types shared across Taquito packages

324 lines (322 loc) 11.9 kB
// ========================================================================================== // parent error classes for Taquito // ========================================================================================== var ValidationResult; (function (ValidationResult) { ValidationResult[ValidationResult["NO_PREFIX_MATCHED"] = 0] = "NO_PREFIX_MATCHED"; ValidationResult[ValidationResult["INVALID_CHECKSUM"] = 1] = "INVALID_CHECKSUM"; ValidationResult[ValidationResult["INVALID_LENGTH"] = 2] = "INVALID_LENGTH"; ValidationResult[ValidationResult["VALID"] = 3] = "VALID"; ValidationResult[ValidationResult["PREFIX_NOT_ALLOWED"] = 4] = "PREFIX_NOT_ALLOWED"; ValidationResult[ValidationResult["INVALID_ENCODING"] = 5] = "INVALID_ENCODING"; ValidationResult[ValidationResult["OTHER"] = 6] = "OTHER"; })(ValidationResult || (ValidationResult = {})); const resultDesc = { [ValidationResult.NO_PREFIX_MATCHED]: 'unsupported Base58 prefix', [ValidationResult.INVALID_CHECKSUM]: 'invalid checksum', [ValidationResult.INVALID_LENGTH]: 'invalid length', [ValidationResult.PREFIX_NOT_ALLOWED]: 'Base58 prefix not allowed in this context', [ValidationResult.INVALID_ENCODING]: 'invalid Base58 encoding', }; /** * @category Error * @description Parent error class all taquito errors to extend from */ class TaquitoError extends Error { } /** * @category Error * @description Error that indicates invalid user inputs */ class ParameterValidationError extends TaquitoError { constructor(message, validationResult, errorDetail) { let detail; let result; let msg; if (message !== undefined) { if (typeof message === 'string') { msg = message; if (validationResult !== undefined) { if (typeof validationResult === 'string') { detail = validationResult; } else { result = validationResult; if (errorDetail !== undefined) { detail = errorDetail; } else { detail = resultDesc[validationResult]; } } } } else { result = message; detail = resultDesc[message]; msg = detail; } } super(msg); this.name = this.constructor.name; this.result = result; this.errorDetail = detail; } } /** * @category Error * @description Error returned by RPC node */ class RpcError extends TaquitoError { } /** * @category Error * @description Error that indicates TezosToolKit has not been configured appropriately */ class TezosToolkitConfigError extends TaquitoError { } /** * @category Error * @description Error that indicates a requested action is not supported by Taquito */ class UnsupportedActionError extends TaquitoError { } /** * @category Error * @description Error during a network operation */ class NetworkError extends TaquitoError { } /** * @category Error * @description Error that indicates user attempts an action without necessary permissions */ class PermissionDeniedError extends TaquitoError { } // ========================================================================================== // common error classes for Taquito // ========================================================================================== /** * @category Error * @description Error that indicates an invalid originated or implicit address being passed or used */ class InvalidAddressError extends ParameterValidationError { constructor(address, errorDetail) { super(`Invalid address "${address}"`, errorDetail); this.address = address; this.name = this.constructor.name; } } class InvalidProofError extends ParameterValidationError { constructor(proof, errorDetail) { super(`Invalid proof "${proof}"`, errorDetail); this.proof = proof; this.name = this.constructor.name; } } class InvalidStakingAddressError extends ParameterValidationError { constructor(address, errorDetail) { super(`Invalid staking address "${address}", you can only set destination as your own address`, errorDetail); this.address = address; this.name = this.constructor.name; } } class InvalidFinalizeUnstakeAmountError extends ParameterValidationError { constructor(address, errorDetail) { super(`The amount can only be 0 when finalizing an unstake`, errorDetail); this.address = address; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid block hash being passed or used */ class InvalidBlockHashError extends ParameterValidationError { constructor(blockHash, errorDetail) { super(`Invalid block hash "${blockHash}"`, errorDetail); this.blockHash = blockHash; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid amount of tez being passed as a parameter */ class InvalidAmountError extends ParameterValidationError { constructor(amount, errorDetail) { super(`Invalid amount "${amount}"`, errorDetail); this.amount = amount; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid derivation path being passed or used */ class InvalidDerivationPathError extends ParameterValidationError { constructor(derivationPath, errorDetail) { super(`Invalid derivation path "${derivationPath}"`, errorDetail); this.derivationPath = derivationPath; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid hex string have been passed or used */ class InvalidHexStringError extends ParameterValidationError { constructor(hexString, errorDetail) { super(`Invalid hex string "${hexString}"`, errorDetail); this.hexString = hexString; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid message being passed or used */ class InvalidMessageError extends ParameterValidationError { constructor(msg, errorDetail) { super(`Invalid message "${msg}"`, errorDetail); this.msg = msg; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates invalid view parameter of a smart contract */ class InvalidViewParameterError extends ParameterValidationError { constructor(viewName, sigs, args, cause, errorDetail) { const message = `Invalid view arguments ${JSON.stringify(args)} received for name "${viewName}" expecting one of the following signatures ${JSON.stringify(sigs)}.`; super(message, errorDetail); this.viewName = viewName; this.sigs = sigs; this.args = args; this.cause = cause; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid private key being passed or used */ class InvalidKeyError extends ParameterValidationError { constructor(errorDetail) { super(`Invalid private key`, errorDetail); this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an Invalid Public Key being passed or used */ class InvalidPublicKeyError extends ParameterValidationError { constructor(publicKey, errorDetail) { const msg = publicKey !== undefined ? `Invalid public key "${publicKey}"` : `Invalid public key`; super(msg, errorDetail); this.publicKey = publicKey; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid signature being passed or used */ class InvalidSignatureError extends ParameterValidationError { constructor(signature, errorDetail) { super(`Invalid signature "${signature}"`, errorDetail); this.signature = signature; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid contract address being passed or used */ class InvalidContractAddressError extends ParameterValidationError { constructor(contractAddress, errorDetail) { super(`Invalid contract address "${contractAddress}"`, errorDetail); this.contractAddress = contractAddress; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid chain id being passed or used */ class InvalidChainIdError extends ParameterValidationError { constructor(chainId, errorDetail) { super(`Invalid chain id "${chainId}"`, errorDetail); this.chainId = chainId; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid public key hash being passed or used */ class InvalidKeyHashError extends ParameterValidationError { constructor(keyHash, errorDetail) { super(`Invalid public key hash "${keyHash}"`, errorDetail); this.keyHash = keyHash; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid operation hash being passed or used */ class InvalidOperationHashError extends ParameterValidationError { constructor(operationHash, errorDetail) { super(`Invalid operation hash "${operationHash}"`, errorDetail); this.operationHash = operationHash; this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates an invalid operation kind being passed or used */ class InvalidOperationKindError extends ParameterValidationError { constructor(operationKind, errorDetail) { super(`Invalid operation kind "${operationKind}"`, errorDetail); this.operationKind = operationKind; this.name = this.constructor.name; } } /** * @category Error * @description General error that indicates something is no longer supported and/or deprecated */ class DeprecationError extends UnsupportedActionError { constructor(message) { super(message); this.name = this.constructor.name; } } /** * @category Error * @description General error that indicates an action is prohibited or not allowed */ class ProhibitedActionError extends UnsupportedActionError { constructor(message) { super(message); this.name = this.constructor.name; } } /** * @category Error * @description Error that indicates a failure in grabbing the public key */ class PublicKeyNotFoundError extends TaquitoError { constructor(pkh, cause) { super(`Public key not found of this address "${pkh}" in either wallet or contract API.`); this.pkh = pkh; this.cause = cause; this.name = this.constructor.name; } } export { DeprecationError, InvalidAddressError, InvalidAmountError, InvalidBlockHashError, InvalidChainIdError, InvalidContractAddressError, InvalidDerivationPathError, InvalidFinalizeUnstakeAmountError, InvalidHexStringError, InvalidKeyError, InvalidKeyHashError, InvalidMessageError, InvalidOperationHashError, InvalidOperationKindError, InvalidProofError, InvalidPublicKeyError, InvalidSignatureError, InvalidStakingAddressError, InvalidViewParameterError, NetworkError, ParameterValidationError, PermissionDeniedError, ProhibitedActionError, PublicKeyNotFoundError, RpcError, TaquitoError, TezosToolkitConfigError, UnsupportedActionError, ValidationResult }; //# sourceMappingURL=taquito-core.es6.js.map