DEV Community

Discussion on: Problem with google cloud function

 
mikenikles profile image
Mike

Thanks for that. The implementation of a few functions is missing, for example getAllFields. Before we dive into that, where do you see the question marks? In your database?

If you print one of the fieldLabel values that contains Hindi characters at the beginning of the cloud function, do you see ? too? What about after you call getAllFields?

Let's try to narrow down where the ? first appear, that will help us determine what causes it.

Thread Thread
 
webjayant profile image
Jayant Raj Singh

I found this question on stackoverflow

stackoverflow.com/questions/605618...

Thread Thread
 
webjayant profile image
Jayant Raj Singh

I logged _request.body at the start of the function.
Having the same problem.

Thread Thread
 
mikenikles profile image
Mike

Given that you have the same problem with the data you receive in the request body, this is likely an issue with how the sender encodes the data.

I wrote a very basic Cloud Function with the following code. (Note: you seem to use Firebase Functions, I didn't test that but don't expect that to be the cause of the problem you see):

exports.helloWorld = (req, res) => {
  let message = req.body.message;
  console.log(message);
  res.status(200).send(message);
};
Enter fullscreen mode Exit fullscreen mode

I called it with the following command from the terminal:

curl -v -X POST -d '{"message": "ā¤†ā¤Ē ā¤Ąā¤ŋā¤œā¤ŋā¤Ÿā¤˛āĨ€ ā¤•āĨā¤¯ā¤ž ā¤•āĨā¤¯ā¤ž ā¤•ā¤°ā¤¤āĨ‡ ā¤šāĨˆ"}' -H "Content-Type: application/json" https://your-cloud-function-url
Enter fullscreen mode Exit fullscreen mode

The log output is: dev-to-uploads.s3.amazonaws.com/i/...

Thread Thread
 
webjayant profile image
Jayant Raj Singh

Ok thanks..
I'll do some testing and will let you know

Thread Thread
 
mikenikles profile image
Mike

Try a most basic command with curl like in my example. Keep me posted, I'll see what I can do to help you troubleshoot this.

Thread Thread
 
webjayant profile image
Jayant Raj Singh

The problem was with the data I was receiving from webhook :D

Thread Thread
 
mikenikles profile image
Mike

Nice find, thanks for sharing. It makes sense given you already saw question marks when you logged the request body. Glad you've resolved that.