Hi PV, and welcome to the community!
This 502 error sounds familiar and maybe this is the cause.
I have a hunch that Netlify Functions based on Amazon Lambda currently only supports Node 12 [source] . So something like a conditional chaining operator (?.) that is only supported in Node 14, a version you are likely using locally would cause this experience.