Skip to content

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

Closed
@natanrolnik

Description

@natanrolnik

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions