Skip to content

Parse.Cloud.httpRequest fails if body is not a string #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
natanrolnik opened this issue Jan 30, 2016 · 6 comments
Closed

Parse.Cloud.httpRequest fails if body is not a string #88

natanrolnik opened this issue Jan 30, 2016 · 6 comments

Comments

@natanrolnik
Copy link
Contributor

Hey Fosco!

In one of my objects, I had a afterSave hook where I do a http post to another Parse app.
However, the body parameter passed is an object, not a string, and this causes the app to throw an exception:

_http_outgoing.js:430
    throw new TypeError('first argument must be a string or Buffer');
    ^

I looked into it, and locally was able to solve it in a easy way. When defining Parse.Cloud.httpRequest in index.js, line 145 I added:

if (typeof options.body === 'object') {
      options.body = JSON.stringify(options.body);
}

It simply converts the object to a string if it's necessary. Is this a correct fix? If so, I can open a PR.

@gfosco
Copy link
Contributor

gfosco commented Jan 31, 2016

Please open the PR. Yeah, it looks like the 'request' module we use only supports a string body.

@natanrolnik
Copy link
Contributor Author

But it works fine when running it in the Parse hosted Cloud Code

@gfosco
Copy link
Contributor

gfosco commented Jan 31, 2016

Because Parse hosted cloud code doesn't use node or the 'request' module... It's a v8 engine with some node-like properties, but mostly custom built.

@natanrolnik
Copy link
Contributor Author

I see... Ok, will add it soon. Thanks!

@natanrolnik
Copy link
Contributor Author

Small JS question: if options.body was not defined, is this code I suggested still safe?

@gfosco
Copy link
Contributor

gfosco commented Jan 31, 2016

Should be, yeah.

@gfosco gfosco closed this as completed Feb 2, 2016
montymxb pushed a commit to montymxb/parse-server that referenced this issue Feb 14, 2016
bernhardharrer pushed a commit to bernhardharrer/parse-server that referenced this issue Feb 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants