Search code examples
parse-platformhttprequesthttpresponseparse-cloud-code

Parse Cloud Function won't return response.success


My cloud function calls a web crawler I'm hosting and retrieves a string back, but I can't response.success the string back to my app if the string is long (it only works with short strings for some reason). Here is my code:

Parse.Cloud.define("search", function(request, response){
    Parse.Cloud.useMasterKey();
    Parse.Cloud.httpRequest({
        url: 'https://xxx.herokuapp.com/',
        params: {
            keyword: request.params.searchTerm
        },
        success: function(httpResponse){
            // The httpResponse.text is received but for some reason
            // will not be returned with response.success
            response.success(httpResponse.text);
        }, error: function(httpResponse){
            response.error(httpResponse);
        }
    });
});

I've been stuck on this problem for several days and any help would be much appreciated.


Solution

  • I made a stupid mistake, all that seems to be needed is the following when returning string to the app:

    response.success(JSON.parse(httpResponse.text));
    

    I'm not sure why this needs to be done with longer strings and it doesn't seem to matter with short strings but I'm sure there is a reason.