UNPKG

stellar-plus

Version:

beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain

80 lines (79 loc) 3.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ABError = exports.AccountBaseErrorCodes = void 0; const error_1 = require("../../../stellar-plus/error"); const axios_1 = require("../../../stellar-plus/error/helpers/axios"); var AccountBaseErrorCodes; (function (AccountBaseErrorCodes) { // AB0 General AccountBaseErrorCodes["AB001"] = "AB001"; // AB1 Account creation AccountBaseErrorCodes["AB100"] = "AB100"; AccountBaseErrorCodes["AB101"] = "AB101"; AccountBaseErrorCodes["AB102"] = "AB102"; AccountBaseErrorCodes["AB103"] = "AB103"; // AB2 Loading from Horizon AccountBaseErrorCodes["AB200"] = "AB200"; AccountBaseErrorCodes["AB201"] = "AB201"; })(AccountBaseErrorCodes || (exports.AccountBaseErrorCodes = AccountBaseErrorCodes = {})); const friendbotNotAvailableError = (error) => { return new error_1.StellarPlusError({ code: AccountBaseErrorCodes.AB001, message: 'Friendbot not available!', source: 'AccountBase', details: 'Friendbot is only available in test networks such as the Testnet and Futurenet. Make sure that the Network configuration object contains a valid Friendbot URL.', meta: { error }, }); }; const failedToCreateAccountWithFriendbotError = (error) => { const axiosError = (0, axios_1.extractAxiosErrorInfo)(error); if (axiosError.type === axios_1.AxiosErrorTypes.AxiosRequestError) { return new error_1.StellarPlusError({ code: AccountBaseErrorCodes.AB101, message: 'Failed request when initializing account with friendbot!', source: 'AccountBase', details: 'The request failed when initializing the account with the friendbot. Make sure that the network is available and that friendbot URL is correct.', meta: { axiosError, error }, }); } if (axiosError.type === axios_1.AxiosErrorTypes.AxiosResponseError) { return new error_1.StellarPlusError({ code: AccountBaseErrorCodes.AB102, message: 'Failed response when initializing account with friendbot!', source: 'AccountBase', details: 'Received a failed response when initializing the account with the friendbot. Make sure the account has not been already initialized.', meta: { axiosError, error }, }); } return new error_1.StellarPlusError({ code: AccountBaseErrorCodes.AB100, message: 'Unknown error when initializing account with friendbot!', source: 'AccountBase', details: 'An unexpected error occured during the friendbot invocation to initialize an account.', meta: { axiosError, error }, }); }; const horizonHandlerNotAvailableError = (error) => { return new error_1.StellarPlusError({ code: AccountBaseErrorCodes.AB200, message: 'Horizon handler not available!', source: 'AccountBase', details: 'Horizon handler is not available. Make sure that the Horizon handler is correctly initialized by providing an instance of Horizon handler or a network configuration when instancing the account.', meta: { error }, }); }; const failedToLoadBalances = (error) => { return new error_1.StellarPlusError({ code: AccountBaseErrorCodes.AB201, message: 'Failed to load balances!', source: 'AccountBase', details: 'Failed to load the account balances from the Horizon server. Make sure that the Horizon handler is correctly initialized and that the account has been correctly initialized.', meta: { error }, }); }; exports.ABError = { failedToCreateAccountWithFriendbotError, friendbotNotAvailableError, horizonHandlerNotAvailableError, failedToLoadBalances, };