Getting a 502 error. Code works in local dev but not when built on Netlify

Please forgive me if this has been covered. I took some time to search through existing posts but I could not find a solution that worked for me. I am new to Netlify and spent quite some time figuring it out. The code works when I run it locally using ‘ntl dev’ in my terminal. It pulls the images from Unsplash and are styled correctly. But when Netlify builds it, the site stops working.
https://infinitescroller.netlify.app
I receive the following error when inspecting the Netlify website.

(This is only letting me upload 1 picture so I will try to add more to comments)

In local development it works and logs a status code of 200 and then logs my photosArray.

It tells me the fetch doesn’t work and server responds with a status of 502

My Netlify Serverless function (picture in comments)

Please let me know if any more information or screenshots from me are needed.

Please help!! Thanks!!

On line 61 at response= await fetch(apiUrl) the red x when hovered on states:
“failed to load resource: the server responded with status 502”

When run locally with ‘ntl dev’ in my Terminal it works just fine and logs my photosArray after doing the fetch to the exact same apiUrl.

Hi @Khudazar, welcome to the community!

By default, a Netlify function only runs for 10 seconds. If your function takes longer than that awaiting then our system will return a 502. Can you make sure that your function isn’t taking longer than that?