This is the current version I have for that function. This is logging all errors to console, but still proceeding to save the objects for whatever reason
Moralis.Cloud.beforeSave("EthNFTTransfers", async request => {
const from_address = request.object.get("from_address");
const to_address = request.object.get("to_address");
try {
if (
from_address == "0x0000000000000000000000000000000000000000" ||
to_address == "0x0000000000000000000000000000000000000000"
) {
throw "Null Address detected";
}
let side;
let group;
const is_synced_address = await Moralis.Cloud.run("isSyncedAddress", {
address: from_address
});
if (is_synced_address) {
group = await Moralis.Cloud.run("getWalletGroupByAddress", {
address: from_address
});
side = "sell";
} else {
group = await Moralis.Cloud.run("getWalletGroupByAddress", {
address: request.object.get("to_address")
});
side = "buy";
}
if(!group) throw "no group for NFTTrade address";
if (!group.startsWith("NFT")) throw "NFTTransfer for non NFT group found";
const metaData = await Moralis.Web3API.token.getNFTMetadata({
address: request.object.get("token_address"),
chain: "eth"
});
if (metaData) {
request.object.set("name", metaData.name);
request.object.set("symbol", metaData.symbol);
}
const decodedLog = await Moralis.Cloud.run("parseNFTLogs", {
transaction_hash: request.object.get("transaction_hash")
});
if (!decodedLog) throw "No OrdersMatched Event found for transaction";
const eth_value = Number(web3.utils.fromWei(decodedLog.price));
const ticker = await Moralis.Cloud.run("getTickerBySymbol", {
symbol: "WETH"
});
const ticker_price = ticker.get("current_price");
const usd_value = Number((eth_value * ticker_price).toFixed(5));
logger.info("NFT ORDERSMATCHED DECODED LOG PRICE " + usd_value)
request.object.set("eth_value", eth_value);
request.object.set("usd", usd_value);
request.object.set("side", side);
request.object.set("group", group);
} catch (error) {
logger.info("Error: " + error);
}
});