Client.request.invoke returning: status: 504 timeout error

Hi,

I’m trying to pass some parameters between a front end to the serverless app, then pass a response back to the front end. (the concept is part of a bigger plan for: Select (fw-select) | Crayons (freshworks.com) with select custom data source.

Using the below I am getting the information from the front end to the serverless and can print the response to confirm this, but nothing is being returned to the front end:
frontend.js

    .invoke('onGetTenants', payload)
    .then(function (response) {
      console.log('Serverless function executed successfully:', response);
    })
    .catch(function (error) {
      console.log('Error while executing serverless function:', error);
    });

server.js

exports = {
  onGetTenants: async function (args) {
    return new Promise((resolve, reject) => {
      const data = args;
      console.log(data);
      if (data.name && data.age) {
        const response = `Hello ${data.name}, you are ${data.age} years old`;
        resolve(response);
      } else {
        const error = 'Invalid data';
        reject(error);
      }
    });
  }
}

I can see the response coming into the server aspect the the data being printed on the console. But from the browser console.logs i’m getting the follow error:

Error while executing serverless function:
{status: 504, message: ‘Timeout error while processing the request.’, errorSource: ‘APP’}

Hi @It-Beer-Nerd ,

To send a response from server.js to the frontend app, you should utilize the renderData() function. You can find more details about this in the documentation provided below.

onGetTenants: async function (args) {
return new Promise((resolve, reject) => {
const data = args;
console.log(data);
if (data.name && data.age) {
const response = Hello ${data.name}, you are ${data.age} years old;
resolve(response);
renderData(null, { data : response})
} else {
const error = ‘Invalid data’;
reject(error);
}
});

Documentation: https://developers.freshworks.com/docs/app-sdk/v2.3/freshdesk/smi-apps/#send-response-to-the-front-end-component

Also, make sure to add timeout in the manifest.json where you registered your SMI function like below.

“functions”: {
“onGetTenants”: {
“timeout”: 20
}
},

Thanks & Regards,
Gopi

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.