Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

fix marketplace not fetching NFT metadata from non-standard contracts #549

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/common/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,21 @@ export async function fetchTokenMetadata(
try {
jsonMetadata = await storage.get(parsedUri);
} catch (err) {
console.warn(
`failed to get token metadata: ${JSON.stringify({
tokenId,
tokenUri,
})} -- falling back to default metadata`,
err,
const unparsedTokenIdUri = tokenUri.replace(
"{id}",
BigNumber.from(tokenId).toString(),
);
jsonMetadata = FALLBACK_METADATA;
try {
jsonMetadata = await storage.get(unparsedTokenIdUri);
} catch (e) {
console.warn(
`failed to get token metadata: ${JSON.stringify({
tokenId: tokenId.toString(),
tokenUri,
})} -- falling back to default metadata`,
);
jsonMetadata = FALLBACK_METADATA;
}
}

return CommonNFTOutput.parse({
Expand Down
3 changes: 3 additions & 0 deletions src/core/classes/ipfs-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ export class IpfsStorage implements IStorage {
uri = resolveGatewayUrl(hash, "ipfs://", this.gatewayUrl);
}
const result = await fetch(uri);
if (!result.ok && result.status === 500) {
throw new Error(`Error fetching ${uri} - Status code ${result.status}`);
}
if (!result.ok && result.status !== 404) {
const nextUrl = this.getNextPublicGateway();
if (nextUrl) {
Expand Down