1

I am trying to run an HTTP Request in an afterSave. It executes correctly, but im getting errors with the response variable I was told to put in the end.

Here is the code

Parse.Cloud.afterSave("ArtPiece", function(request) {
var artistURL = 'http://www.gallery-admin-dev.iartview.com/Gilmans/imageSave.php';

var artPiece = request.object;

if (typeof request.image === "undefined") {

    var pieceName = artPiece.get("piece_name");

    var url = artPiece.get("imageURL");

    Parse.Cloud.httpRequest({
        url: artistURL,
        params: {
          pieceName : pieceName,
          url : url
        },
        success: function(httpResponse) {
            response.success();
        },
        error: function(httpResponse) {
            response.error('Request failed with response code ' + httpResponse.status)
        }
    }); 
}
});

The problem is the success and error functions.

Things I have tried that have not worked: Putting response as a second parameter in the afterSave Call (it says can not call .success of an undefined variable)

Getting rid of the response lines of code (Result: success/error was not called)

Calling Response as its own function response('Request failed with response code ' + httpResponse.status) it just says response is undefined.

I dont really care about having any response or not, I just want the code to work properly.

How is this 'response' variable supposed to be set up?

Thank you!

2
  • How do you know the code, (as is), is failing? Commented Dec 23, 2015 at 18:45
  • It doesnt always fail, it usually gets about half of the art_pieces done Commented Dec 23, 2015 at 18:47

1 Answer 1

1

There was an extra url in the parameters, a reference to a probably undefined artistURL...

Parse.Cloud.afterSave("ArtPiece", function(request) {
    var artistURL = 'http://www.gallery-admin-dev.iartview.com/Gilmans/imageSave.php';
    var artPiece = request.object;
    if (typeof request.image === "undefined") {
        var pieceName = artPiece.get("piece_name");
        var url = artPiece.get("imageURL");
        var params = { pieceName : pieceName };
        return Parse.Cloud.httpRequest({ url: artistURL, params: params });
    }
});
Sign up to request clarification or add additional context in comments.

5 Comments

Awesome suggestion! unforunately I still get: Result: TypeError: Cannot call method 'error' of undefined. Could this be some type of timeout issue? it still is thinking response is undefined regardless
No. Its my bad. after save doesn't take a response param. before does. Sorry about this. Maybe it was the syntax error in the OP function. Please see edit.
No problem, Thank you, The second url is actually necessary to the params, but I added it back myself. Now there are no errors, but still some of the images are not showing up for some reason. I will have to do more research to see why, but having no errors is helpful
Im a the point where I get: 'Result: Execution timed out' and 'Result: success/error was not called' in the error logs. Is it possible I am missing a call to success or error
Ok good. Now we have a clear diagnosis. Try executing that req in a browser or with CURL and see what's going on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.