[SOLVED] My Hello function doesn't return anything

code

Moralis.Cloud.define("allUsernames", async (request) => {
  const query = new Moralis.Query("User");
  const results = await query.find({ useMasterKey: true });
  // return results;
  return results.map({username, createdAt, updatedAt} => ({username, createdAt, updatedAt}));
});

Moralis.Cloud.define("allUsers", async (request) => {
  const query = new Moralis.Query("User");
  const results = await query.find({ useMasterKey: true });
  return results;
});

Moralis.Cloud.define("hello", async (request) => {
  return "world!";
});

I got error with message

// 20220605203736
// https://7olxsw72bp15.usemoralis.com:2053/server/functions/hello?_ApplicationId=CL4l7a0ddvU0SAZdDJkqFSPs9BTUm2lcX9HW4ZYG

{
  "code": 141,
  "error": "Invalid function: \"hello\""
}

can anyone help?

Thanks,
Jay Lin

It’s an issue with your allUsernames syntax which isn’t being picked up by the interface. It should be:

Moralis.Cloud.define("allUsernames", async (request) => {
  const query = new Moralis.Query("User");
  const results = await query.find({ useMasterKey: true });
  // return results;
  return results.map(({username, createdAt, updatedAt}) => ({username, createdAt, updatedAt}));
});

Your hello function should work after this.

1 Like

That works! Thanks~!

Also I would suggest Moralis could catch the JS error in console.

Great. The error is in the server logs but just not detected by the cloud function UI.