Skip to content

Commit

Permalink
Going to try catch all api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jongan69 committed Jan 5, 2025
1 parent fad7a08 commit a663ae2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/utils/bitcoinPrice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export const fetchBitcoinPrice = async () => {
const response = await fetch(`https://api.coindesk.com/v1/bpi/currentprice.json`);
const data = await response.json();
const price = data.bpi.USD.rate;
return price;
try {
const response = await fetch(`https://api.coindesk.com/v1/bpi/currentprice.json`);
const data = await response.json();
const price = data.bpi.USD.rate;
return price;
} catch (error) {
console.error("Error fetching Bitcoin price:", error);
return null;
}
}
14 changes: 9 additions & 5 deletions src/utils/fetchIpfsMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ export const fetchIpfsMetadata = async (cid: string) => {
// console.log(`No IPFS CID provided: ${cid}`);
return { imageUrl: DEFAULT_IMAGE_URL };
}

const response = await fetch(`/api/ipfs/ipfs-proxy?cid=${cid}`);
if (!response.ok) return { imageUrl: DEFAULT_IMAGE_URL };
return await response.json();
try {
const response = await fetch(`/api/ipfs/ipfs-proxy?cid=${cid}`);
if (!response.ok) return { imageUrl: DEFAULT_IMAGE_URL };
return await response.json();
} catch (error) {
console.error("Error Fetching IPFS Data Using Default:", DEFAULT_IMAGE_URL);
return { imageUrl: DEFAULT_IMAGE_URL };
}
} catch (error) {
console.error("Error Fetching IPFS Data Using Default:", DEFAULT_IMAGE_URL);
console.error("Error Fetching IPFS Data:", error);
return { imageUrl: DEFAULT_IMAGE_URL };
}
};

0 comments on commit a663ae2

Please sign in to comment.