Back

CLOUD: Function res.json is not working (node)

  • 0
  • Functions
  • Cloud
ggsotillo
12 Aug, 2024, 14:06

Hi I'm receiving "Return statement missing. return context.res.empty() if no response is expected." when calling a function from the console.

code: require('dotenv').config();

const lambda = new AWS.Lambda({ accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, region: process.env.AWS_REGION });

module.exports = async function ({req, res, log, error}) { log('Starting function V2...'); log('req:'); console.log(req); log('res:'); console.log(res);

TypeScript
  const body = typeof req.body === 'string' ? JSON.parse(req.body) : req.body;

  const { functionName } = body;




try {
    // Invoke action
 
    
    res.json({
        success: true,
        message: "Action invoked successfully",
        result: JSON.parse(result.Payload)
    });

} catch (error) {
    // Maneja cualquier error
    res.json({
        success: false,
        message: "Error invoking Action",
        error: error.message
    });

} 

};

Errors: Return statement missing. return context.res.empty() if no response is expected.


TL;DR
Function `res.json()` is not working because a return statement is missing. Use `return res.json()` instead of just `res.json()`.
Al
12 Aug, 2024, 14:53

Use return res.json() instead of just calling res.json()

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more