By assuming that the body HAS to be json parseable, all cloud functions will throw an error if the request is not json.
Summary
The user had an issue where their request body was not being parsed as JSON. Another user clarified that the body will only be parsed as JSON if the content type header is set to application/json. The user thanked them for the help. They also asked if the parsing of the body depends on what triggered the execution and if there were any parse errors from user events. The users then discussed the issue further and one of them opened an issue on GitHub. They mentioned that the recent changes to the system helped reduce assumptions but this issue still exists. It was pointed out that making this change will require both backend and frontend refactors. The user mentioned
Tanner Meade
Rank 4: Virtual Machine
Oct 3, 2023, 17:17
So everyone who has existing functions that accept string request bodies or anything not json parsable (or anyone who wants to in the future) can no longer do that.
Tanner Meade
Rank 4: Virtual Machine
Oct 3, 2023, 17:17
All changes to make this work going forward require not only backend refactors, but frontend changes too.
Tanner Meade
Rank 4: Virtual Machine
Oct 3, 2023, 17:22
It would be really nice if cloud functions stop assuming things like this. The recent big change helped reduce these assumptions by a lot, but this is still an issue.
this only applies to functions triggered by event...which in those cases, the body should always be JSON
Tanner Meade
Rank 4: Virtual Machine
Oct 3, 2023, 18:36
aahh -- make sense
Tanner Meade
Rank 4: Virtual Machine
Oct 3, 2023, 18:37
I thought I was getting this error though not in that situation. I'll triple check and report back.
Drake
Oct 3, 2023, 18:38
are you getting a parse error from a user event?
Tanner Meade
Rank 4: Virtual Machine
Oct 4, 2023, 04:02
It's not through an error. Thanks for the help. context.req.body is giving me a string, so I'm not sure what to expect. Will body be parsed / not parsed depending on what triggered the execution?
Drake
Oct 4, 2023, 04:02
Body will only be parsed as JSON if the content type header is application/json
Tanner Meade
Rank 4: Virtual Machine
Oct 4, 2023, 04:03
ahh gotcha -- that makes more sense.
Tanner Meade
Rank 4: Virtual Machine
Oct 4, 2023, 04:03
[SOLVED] v1.4.4 Functions Body Parsed / Not Parsed