Wanderlust step 41

Hello everyone,

I am currently working on the wanderlust project, and I am at step 41 :“For a real challenge, try fetching venue photos! This will require an additional request for venue details for each venue, as the photo information is not returned in the initial request”

I am a little confused. Here is my code to retrieve the photo of the place in the json object.

const getPhotoVenue = async (venueId) => {
   const urlToFetch = `https://api.foursquare.com/v2/venues/${venueId}/photos?&limit=1&client_id=${clientId}&client_secret=${clientSecret}&v=20210712`;
  try { 
    const response = await fetch(urlToFetch);
      const jsonResponse = await response.json();
      if (jsonResponse.response.photos.count>0){
      const photo =`${jsonResponse.response.photos.items[0].prefix}300x300${jsonResponse.response.photos.items[0].suffix}`; 
     return photo;
    } throw new Error('Erreur');

Then in another “RenderVenues” function a little further down in the code, I would like to recover my photo like this:

const venuePhoto = getPhotoVenue(venues[index].id);

But this does not show me the photo but [object Promise].

I don’t understand because it seemed to me that the word “await” allowed to return the value of the resolved promise.
In the same idea, I do not understand why in the exercise, we use the word “then” whereas it seemed to me that the use of “await” in an asychronous function made it possible to do without the “then”.

  .then(venue => renderVenues(venue))

Thank you in advance for your help and sorry if my english is not very good, I am French

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.