0
let metadata = allNFTs.map(async (e) => {
      try {
        const res = JSON.parse(e.metadata.attributes);
        return res;
      } catch (err) {
        // throw err;
        let config = {
          method: "get",
          url: `http://localhost:3000/api/fetch`,
          header: {
            "Content-Type": "application/json",
          },
        };
        const res = await axios(config);
        console.log(res.data.attributes);
        return res.data.attributes;
      }
    });
console.log(metadata);

I want use try catch method like this but all i can get bunch of promises on my console

enter image description here

When i tried if statement my next.js app throwing me that error. I want to do something if e.metadata.attributes is empty or null or undefined but my app throwing errors.

  • 1
    `async` functions **ALWAYS** return a Promise - `Promise.all(metadata).then(console.log)` will output the values – Bravo Apr 23 '22 at 23:56

0 Answers0