renderData inconsistency in Freshservice

Hi! I’m currently facing an issue during a Freshservice integration.

In the handler file of my app, I’m invoking a function that makes an API call to server.js. The API in server.js is being triggered successfully every time, and I can see the expected output being logged in the terminal. However, the issue arises when trying to render the response back to the handler. Out of 10 attempts, the handler receives the response correctly only once. In the remaining cases, the response doesn’t come through, and we encounter an error — I’ve attached the error message, code snippets, and output screenshots below.

Any guidance or suggestions would be greatly appreciated!

handler.js:
async function getPhoneID(accountKey){
//LIST PHONENUMBERID
try{
let phoneNumbers = await client.request.invoke(‘listPhoneNumberServer’,{“accountKey”:accountKey});
//Even the below line is not printing in UI
console.log(“phoneNumbers”,phoneNumbers)
const phoneData = phoneNumbers.message;
const phoneID = phoneData.id
console.log(“phoneID”,phoneID)
return phoneID

  }catch(err){
    console.log("Error fetching phoneNumbers:", err);
  }
}

server.js:
listPhoneNumberServer: async function (args) {
try {
console.log(“listPhoneNumberServer args”,args)

    let result = await $request.invokeTemplate("listPhoneNumber", {context: {
      accountKey: args.accountKey,
      pageSize:10
    }});
    let response = result.response
    console.log("listPhoneNumberServer response",response)
    
    //tried this initially - didn't work
    renderData({ status: 200, message: JSON.stringify(result.response)});
    //tried as per documentation - didn't work
    renderData(null,{"message":JSON.stringify(response)})
  }
  catch (error) {
    console.error("Error listPhoneNumberServer");
    renderData({ status: 403, message: "Failed to fetch phone numbers" });
    console.error(error);

  }
},

Output of server in terminal:


Output in UI from handler: