Netlify function payload is null and returning error 502 in production but works fine in development. Any help please

Hi Netlify,
I created a netlify function (POST) for creating payment intent and sent the price over. On the handler, it all works pretty well in development but when deployed, the function returns error 502 and the response is - “error decoding lambda response: invalid status code returned from lambda: 0” - I have the call code and the handler code below. Any help to resolving this will be appreciated.

FRONTEND CALL CODE

const createPaymentIntent = async () => {
		const price = totalDue;

		if (user) {
			try {
				const { data } = await axios.post(
					"/.netlify/functions/create-payment-intent-book",
					JSON.stringify({ price })
				);
				setClientSecret(data.clientSecret);
				setAllowProceed(true);
			} catch (error) {
				set_Error(
					error?.response?.data ? "Please contact hairposey Admin..." : ""
				);
			}
		} else if (userEmail) {
			if (ValidateEmail(userEmail)) {
				if (emailError) {
					setEmailError(false);
				}
				try {
					const { data } = await axios.post(
						"/.netlify/functions/create-payment-intent-book",
						JSON.stringify({ price })
					);
					setClientSecret(data.clientSecret);
					setAllowProceed(true);
				} catch (error) {
					set_Error(
						error?.response?.data ? "Please contact hairposey Admin..." : ""
					);
				}
			} else {
				setEmailError(true);
			}
		}
	};

HANDLER CODE -

exports.handler = async function (event, context) {

	const { price } = JSON.parse(event.body);

	if (event.body) {
		try {
			const paymentIntent = await stripe.paymentIntents.create({
				amount: price * 100,
				currency: "cad",
			});

			return {
				statusCode: 200,
				body: JSON.stringify({ clientSecret: paymentIntent.client_secret}),
			};
		} catch (error) {
			return {
				statusCodes: 500,
				body: JSON.stringify({ msg: error.message }),
			};
		}
	}
	return { statusCode: 200, body: "Please Create Payment Intent" };
};

Hmm, I don’t see any error in this code. Is this all the code or have you excluded some parts? Could you share your site name or give us a repo that we can test?

Hi @hrishikesh
Thanks for the response. This is all the code, I am surprise I am getting the error as all seems to work in development.

It brings me back to my other question:

The site name is - https://www.hairposey.com

When exactly do you get that error? I tried sending a POST request to your function and got a response just fine. Do we need to do something specific to trigger that error?

I get error just when i click the submit button that triggers the create-payment-intent function. The 502 error came back. Payload was equal to null and something about statusCode being invalid

Hi @hrishikesh,
Thank you for your help.
Figured out the issue. There was an error in my code. the statusCode was spelt with an “s” which was responsible for the error 502 I was getting. All good now. Thanks.

Glad to hear and thanks for letting us know @_tony ! :raised_hands: