Skip to content

Commit

Permalink
Add better messaging when failing to parse NFT (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
thebrianchen authored Nov 16, 2022
1 parent 4a1842b commit db16e15
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,32 @@ export function getBaseNftFromRaw(
}

export function getNftFromRaw(rawNft: RawNft): Nft {
const tokenType = parseNftTokenType(rawNft.id.tokenMetadata?.tokenType);
const spamInfo = parseSpamInfo(rawNft.spamInfo);
return {
contract: {
address: rawNft.contract.address,
name: rawNft.contractMetadata?.name,
symbol: rawNft.contractMetadata?.symbol,
totalSupply: rawNft.contractMetadata?.totalSupply,
tokenType
},
tokenId: parseNftTokenId(rawNft.id.tokenId),
tokenType,
title: rawNft.title,
description: parseNftDescription(rawNft.description),
timeLastUpdated: rawNft.timeLastUpdated,
metadataError: rawNft.error,
rawMetadata: rawNft.metadata,
tokenUri: parseNftTokenUri(rawNft.tokenUri),
media: parseNftTokenUriArray(rawNft.media),
spamInfo
};
try {
const tokenType = parseNftTokenType(rawNft.id.tokenMetadata?.tokenType);
const spamInfo = parseSpamInfo(rawNft.spamInfo);

return {
contract: {
address: rawNft.contract.address,
name: rawNft.contractMetadata?.name,
symbol: rawNft.contractMetadata?.symbol,
totalSupply: rawNft.contractMetadata?.totalSupply,
tokenType
},
tokenId: parseNftTokenId(rawNft.id.tokenId),
tokenType,
title: rawNft.title,
description: parseNftDescription(rawNft.description),
timeLastUpdated: rawNft.timeLastUpdated,
metadataError: rawNft.error,
rawMetadata: rawNft.metadata,
tokenUri: parseNftTokenUri(rawNft.tokenUri),
media: parseNftTokenUriArray(rawNft.media),
spamInfo
};
} catch (e) {
throw new Error('Error parsing the NFT response: ' + e);
}
}

export function getNftSalesFromRaw(
Expand Down

0 comments on commit db16e15

Please sign in to comment.