mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
handle error messages
This commit is contained in:
parent
7ec2cb38e4
commit
d574782b14
@ -82,7 +82,7 @@ export class Pool extends PoolFactory {
|
||||
)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error('Pool.setup failed:' + e)
|
||||
console.error(`ERROR: Failed to setup a pool: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -134,7 +134,7 @@ export class Pool extends PoolFactory {
|
||||
.approve(spender, amount)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERRPR: Failed to approve spender to spend tokens : ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -152,7 +152,7 @@ export class Pool extends PoolFactory {
|
||||
const balance = await token.methods.balanceOf(account).call()
|
||||
result = this.web3.utils.fromWei(balance)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get shares of pool : ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -190,7 +190,7 @@ export class Pool extends PoolFactory {
|
||||
)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to add tokens to pool: ${e.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,7 +215,7 @@ export class Pool extends PoolFactory {
|
||||
.setSwapFee(this.web3.utils.toWei(fee))
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to set pool swap fee: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -235,7 +235,7 @@ export class Pool extends PoolFactory {
|
||||
.finalize()
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to finalize pool: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -251,7 +251,7 @@ export class Pool extends PoolFactory {
|
||||
try {
|
||||
result = await pool.methods.getNumTokens().call()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get number of tokens: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -268,7 +268,7 @@ export class Pool extends PoolFactory {
|
||||
const result = await pool.methods.totalSupply().call()
|
||||
amount = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get total supply of pool shares: ${e.message}`)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
@ -284,7 +284,7 @@ export class Pool extends PoolFactory {
|
||||
try {
|
||||
result = await pool.methods.getCurrentTokens().call()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get tokens composing this pool: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -300,7 +300,7 @@ export class Pool extends PoolFactory {
|
||||
try {
|
||||
result = await pool.methods.getFinalTokens().call()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get the final tokens composing this pool`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -316,7 +316,7 @@ export class Pool extends PoolFactory {
|
||||
try {
|
||||
result = await pool.methods.getController().call()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get pool controller address: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -342,7 +342,7 @@ export class Pool extends PoolFactory {
|
||||
.setController(controllerAddress)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to set pool controller: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -359,7 +359,7 @@ export class Pool extends PoolFactory {
|
||||
try {
|
||||
result = await pool.methods.isBound(token).call()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to check if a token bounded to a pool: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -377,7 +377,7 @@ export class Pool extends PoolFactory {
|
||||
const result = await pool.methods.getBalance(token).call()
|
||||
amount = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get how many tokens are in the pool: ${e.message}`)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
@ -393,7 +393,7 @@ export class Pool extends PoolFactory {
|
||||
try {
|
||||
result = await pool.methods.isFinalized().call()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to check whether pool is finalized: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -410,7 +410,7 @@ export class Pool extends PoolFactory {
|
||||
const result = await pool.methods.getSwapFee().call()
|
||||
fee = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get pool fee: ${e.message}`)
|
||||
}
|
||||
return fee
|
||||
}
|
||||
@ -428,7 +428,7 @@ export class Pool extends PoolFactory {
|
||||
const result = await pool.methods.getNormalizedWeight(token).call()
|
||||
weight = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get normalized weight of a token: ${e.message}`)
|
||||
}
|
||||
return weight
|
||||
}
|
||||
@ -446,7 +446,7 @@ export class Pool extends PoolFactory {
|
||||
const result = await pool.methods.getDenormalizedWeight(token).call()
|
||||
weight = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error('ERROR: Failed to get denormalized weight of a token in pool')
|
||||
}
|
||||
return weight
|
||||
}
|
||||
@ -463,7 +463,7 @@ export class Pool extends PoolFactory {
|
||||
const result = await pool.methods.getTotalDenormalizedWeight().call()
|
||||
weight = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error('ERROR: Failed to get total denormalized weight in pool')
|
||||
}
|
||||
return weight
|
||||
}
|
||||
@ -503,7 +503,7 @@ export class Pool extends PoolFactory {
|
||||
)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -543,7 +543,7 @@ export class Pool extends PoolFactory {
|
||||
)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to swap exact amount out: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -580,7 +580,7 @@ export class Pool extends PoolFactory {
|
||||
.joinPool(this.web3.utils.toWei(poolAmountOut), weiMaxAmountsIn)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to join pool: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -614,7 +614,7 @@ export class Pool extends PoolFactory {
|
||||
.exitPool(this.web3.utils.toWei(poolAmountIn), weiMinAmountsOut)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to exit pool: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -648,7 +648,7 @@ export class Pool extends PoolFactory {
|
||||
)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to pay tokens in order to join the pool: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -682,7 +682,7 @@ export class Pool extends PoolFactory {
|
||||
)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error('ERROR: Failed to join swap pool amount out')
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -716,7 +716,7 @@ export class Pool extends PoolFactory {
|
||||
)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to pay pool shares into the pool: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -750,7 +750,7 @@ export class Pool extends PoolFactory {
|
||||
)
|
||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to specify token amount out that will get out of the pool. ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -773,7 +773,7 @@ export class Pool extends PoolFactory {
|
||||
const result = await pool.methods.getSpotPrice(tokenIn, tokenOut).call()
|
||||
price = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error('ERROR: Failed to get spot price of swapping tokenIn to tokenOut')
|
||||
}
|
||||
return price
|
||||
}
|
||||
@ -796,7 +796,7 @@ export class Pool extends PoolFactory {
|
||||
const result = await pool.methods.getSpotPriceSansFee(tokenIn, tokenOut).call()
|
||||
price = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get spot price of swapping tokenIn to tokenOut without fees: ${e.message}`)
|
||||
}
|
||||
return price
|
||||
}
|
||||
@ -825,7 +825,7 @@ export class Pool extends PoolFactory {
|
||||
.call()
|
||||
amount = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to calculate input token-pair amount giving output token-pair amount: ${e.message}`)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
@ -854,7 +854,7 @@ export class Pool extends PoolFactory {
|
||||
.call()
|
||||
amount = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to calculate output token-pair amount giving the input token-pair amount : ${e.message}`)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
@ -883,7 +883,7 @@ export class Pool extends PoolFactory {
|
||||
.call()
|
||||
amount = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to calculate PoolOutGivenSingleIn : ${e.message}`)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
@ -912,7 +912,7 @@ export class Pool extends PoolFactory {
|
||||
.call()
|
||||
amount = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
@ -941,7 +941,7 @@ export class Pool extends PoolFactory {
|
||||
.call()
|
||||
amount = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${e.message}`)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
@ -970,7 +970,7 @@ export class Pool extends PoolFactory {
|
||||
.call()
|
||||
amount = this.web3.utils.fromWei(result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to calculate PoolInGivenSingleOut : ${e.message}`)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
|
@ -29,12 +29,12 @@ export class PoolFactory {
|
||||
*/
|
||||
async createPool(account: string): Promise<string> {
|
||||
if (this.web3 === null) {
|
||||
console.error('Web3 object is null')
|
||||
console.error('ERROR: Web3 object is null')
|
||||
return null
|
||||
}
|
||||
|
||||
if (this.factoryAddress === null) {
|
||||
console.error('bfactoryAddress is null')
|
||||
console.error('ERROR: bfactoryAddress is null')
|
||||
return null
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ export class PoolFactory {
|
||||
try {
|
||||
pooladdress = transactiondata.events.BPoolRegistered.returnValues[0]
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to create new pool: ${e.message}`)
|
||||
}
|
||||
return pooladdress
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ export class DataTokens {
|
||||
const estGas = await factory.methods
|
||||
.createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap))
|
||||
.estimateGas(function (err: string, estGas: string) {
|
||||
if (err) console.log('Datatokens: ' + err)
|
||||
if (err) console.error(`ERROR: Datatokens : ${err}`)
|
||||
return estGas
|
||||
})
|
||||
// Invoke createToken function of the contract
|
||||
@ -108,7 +108,7 @@ export class DataTokens {
|
||||
try {
|
||||
tokenAddress = trxReceipt.events.TokenCreated.returnValues[0]
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to create datatoken : ${e.message}`)
|
||||
}
|
||||
return tokenAddress
|
||||
}
|
||||
@ -157,7 +157,7 @@ export class DataTokens {
|
||||
const estGas = await datatoken.methods
|
||||
.mint(destAddress, this.web3.utils.toWei(amount))
|
||||
.estimateGas(function (err, estGas) {
|
||||
if (err) console.log('Datatokens: ' + err)
|
||||
if (err) console.error(`ERROR: Datatokens : ${err}`)
|
||||
return estGas
|
||||
})
|
||||
|
||||
@ -373,7 +373,7 @@ export class DataTokens {
|
||||
.send({ from: address, gas: 600000 })
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to start order : ${e.message}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ export class OceanFixedRateExchange {
|
||||
})
|
||||
exchangeId = trxReceipt.events.ExchangeCreated.returnValues[0]
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to create new exchange: ${e.message}`)
|
||||
}
|
||||
return exchangeId
|
||||
}
|
||||
@ -144,7 +144,7 @@ export class OceanFixedRateExchange {
|
||||
})
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to buy datatokens: ${e.message}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -178,7 +178,7 @@ export class OceanFixedRateExchange {
|
||||
.setRate(exchangeId, this.web3.utils.toWei(String(newRate)))
|
||||
.estimateGas(function (err, estGas) {
|
||||
if (err) {
|
||||
// console.log('FixedPriceExchange: ' + err)
|
||||
console.error(`ERROR: FixedPriceExchange: ${err.message}`)
|
||||
return DEFAULT_GAS_LIMIT
|
||||
}
|
||||
return estGas
|
||||
@ -214,7 +214,7 @@ export class OceanFixedRateExchange {
|
||||
.toggleExchangeState(exchangeId)
|
||||
.estimateGas(function (err, estGas) {
|
||||
if (err) {
|
||||
// console.log('FixedPriceExchange: ' + err)
|
||||
console.error(`ERROR: FixedPriceExchange: ${err.message}`)
|
||||
estGas = DEFAULT_GAS_LIMIT
|
||||
}
|
||||
return estGas
|
||||
@ -248,7 +248,7 @@ export class OceanFixedRateExchange {
|
||||
.toggleExchangeState(exchangeId)
|
||||
.estimateGas(function (err, estGas) {
|
||||
if (err) {
|
||||
// console.log('FixedPriceExchange: ' + err)
|
||||
console.error(`ERROR: FixedPriceExchange: ${err.message}`)
|
||||
estGas = DEFAULT_GAS_LIMIT
|
||||
}
|
||||
return estGas
|
||||
|
@ -100,14 +100,14 @@ export class OnChainMetadataCache {
|
||||
consumerAccount: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if (!this.DDOContract) {
|
||||
console.error('Missing DDOContract')
|
||||
console.error('ERROR: Missing DDOContract')
|
||||
return null
|
||||
}
|
||||
try {
|
||||
/* const estGas = await this.DDOContract.methods
|
||||
.create(didZeroX(did), flags, data)
|
||||
.estimateGas(function (err, estGas) {
|
||||
if (err) console.log('OnChainMetadataCacheEstimateGas: ' + err)
|
||||
if (err) console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
|
||||
return estGas
|
||||
})
|
||||
*/
|
||||
@ -116,7 +116,7 @@ export class OnChainMetadataCache {
|
||||
.send({ from: consumerAccount })
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
console.error(e.message)
|
||||
console.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,7 @@ export class OnChainMetadataCache {
|
||||
consumerAccount: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if (!this.DDOContract) {
|
||||
console.error('Missing DDOContract')
|
||||
console.error('ERROR: Missing DDOContract')
|
||||
return null
|
||||
}
|
||||
try {
|
||||
@ -145,7 +145,7 @@ export class OnChainMetadataCache {
|
||||
.send({ from: consumerAccount })
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to update raw DDO : ${e.message}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -171,7 +171,7 @@ export class OnChainMetadataCache {
|
||||
})
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to transfer DDO ownership : ${e.message}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -201,7 +201,7 @@ export class OnChainMetadataCache {
|
||||
hex += '' + hexChar[(message[i] >> 4) & 0x0f] + hexChar[message[i] & 0x0f]
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get hex message value : ${e.message}`)
|
||||
}
|
||||
const hexMessage = '0x' + hex
|
||||
return hexMessage
|
||||
|
@ -111,7 +111,7 @@ export default class Account extends Instantiable {
|
||||
})
|
||||
result = this.web3.utils.fromWei(await token.methods.balanceOf(this.id).call())
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to get the balance: ${e.message}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ export class Assets extends Instantiable {
|
||||
const totalCost = new BigNumber(String(providerData.numTokens))
|
||||
if (balance.isLessThan(totalCost)) {
|
||||
console.error(
|
||||
'Not enough funds. Needed ' +
|
||||
'ERROR: Not enough funds Needed ' +
|
||||
totalCost.toString() +
|
||||
' but balance is ' +
|
||||
balance.toString()
|
||||
@ -515,7 +515,7 @@ export class Assets extends Instantiable {
|
||||
)
|
||||
if (txid) return txid.transactionHash
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(`ERROR: Failed to order: ${e.message}`)
|
||||
}
|
||||
return null
|
||||
}
|
||||
@ -572,7 +572,6 @@ export class Assets extends Instantiable {
|
||||
consumeUrl += `&tokenAddress=${dtAddress}`
|
||||
consumeUrl += `&transferTxId=${txId}`
|
||||
const serviceConnector = new WebServiceConnector(this.logger)
|
||||
console.log(consumeUrl)
|
||||
try {
|
||||
await serviceConnector.downloadFile(consumeUrl)
|
||||
} catch (e) {
|
||||
@ -580,7 +579,6 @@ export class Assets extends Instantiable {
|
||||
this.logger.error(e)
|
||||
throw e
|
||||
}
|
||||
|
||||
return serviceEndpoint
|
||||
}
|
||||
|
||||
|
@ -395,7 +395,7 @@ export class Compute extends Instantiable {
|
||||
// check if raw algo is allowed
|
||||
if (service.attributes.main.privacy)
|
||||
if (!service.attributes.main.privacy.allowRawAlgorithm) {
|
||||
console.error('This service does not allow Raw Algo')
|
||||
console.error('ERROR: This service does not allow raw algorithm')
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -407,7 +407,7 @@ export class Compute extends Instantiable {
|
||||
if (
|
||||
!service.attributes.main.privacy.trustedAlgorithms.includes(algorithmDid)
|
||||
) {
|
||||
console.error('This service does not allow this Algo')
|
||||
console.error('ERROR: This service does not allow this algorithm')
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ export class ConfigHelper {
|
||||
|
||||
return configAddresses
|
||||
} catch (e) {
|
||||
console.error(`Could not load local contract address file: ${e.message}`)
|
||||
console.error(`ERROR: Could not load local contract address file: ${e.message}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user