Welcome, its me again ^^
short little question.
i am creating a Cloud Job to update the Database with historical prices and its working so there is no problem BUT once there is an error from the getTokenPrice function, the job just stops. The thing is, it does not seem i can catch it anyhow so i could say like “if error xy…continue”
the error i get is “No pools found with enough liquidity, to calculate the price” wich obviously is because there is no LP pool. but how can i fetch this error in my function to let the function set the price to 0 instead of killing the whole job?
thats the current function i use:
async function getHistoricalPrices(database,jdata)
{
const logger = Moralis.Cloud.getLogger();
logger.info("Started Function");
for(transfer of jdata)
{
logger.info(JSON.stringify(transfer));
const options = {address: transfer.get("token_address"),chain: "bsc",to_block: transfer.get("block_number"),};
let usdprice = 0;
price = await Moralis.Web3API.token.getTokenPrice(options);
logger.info("################## "+JSON.stringify(price));
if (typeof price.usdPrice !== 'undefined') {
usdPrice = price.usdPrice;
}
else
{
usdPrice = 0;
}
logger.info("Starting saving in Database "+database);
const BscTransfersx = Moralis.Object.extend(database);
const queryx = new Moralis.Query(BscTransfersx);
queryx.equalTo("objectId", transfer.get("objectId"));
const resultx = await queryx.first({useMasterKey:true});
resultx.set("usdval",usdPrice);
await resultx.save(null, {useMasterKey:true});
}
}
i tried with try catch and everything but does not work … also i assumed there could something be like price.message (like it is if i use the Web3API with curl on PHP) but also thats not existing… so it seems i am missing something. i also did JSON.stringify(price) to see if there is any output… but the logger does not even trigger, because it directly fails on the getTokenPrice function itself.
So just to summarize: How can i fetch that error so i can continue the loop, instead of killing the whole job.
Thank you for the help