tpimh
tpimh

Reputation: 578

response.error is not a function in Parse Cloud Code

I'm running parse-server and trying to create a parse cloud code function. I started with this oversimplified example:

Parse.Cloud.define("createContent", function(request, response) {
  response.error("not implemented");
});

I can call my function using the REST API with curl and get a JSON with an error message: {"code":141,"error":"response.error is not a function"} (this is not the error message I expected). Upon further examination response object turned out to be null.

This is the respective section of the log:

error: Failed running cloud function createContent for user undefined with:
Input: {}
Error: {"code":141,"message":"response.error is not a function"} functionName=createContent, code=141, message=response.error is not a function, , user=undefined
error: response.error is not a function code=141, message=response.error is not a function

Upvotes: 2

Views: 2405

Answers (1)

flovilmart
flovilmart

Reputation: 1769

It looks like you're running the latest version of the server. Please follow the migration guides:

https://github.com/parse-community/parse-server/blob/master/3.0.0.md

For example, now you'll need to write:

Parse.Cloud.define("createContent", function(request, response) {
  throw "not implemented";
});

// also valid
Parse.Cloud.define("createContent", function(request, response) {
  throw new Error("not implemented");
});

// returning a rejected promise
Parse.Cloud.define("createContent", function(request, response) {
  return Promise.reject("not implemented");
});

Upvotes: 10

Related Questions