Following is my code where I have a nodejs Google function, and I am invoking a REST API. But in below code snippet, I get the response, but need to get response out of try-catch so I can do further processing.
exports.postFunction = (req, res) => {
try{
fetch('https://someapi', {
method: 'post',
body: JSON.stringify(req.body),
headers: {'Content-Type': 'application/json'},
})
.then(res => res.json())
.then(json => console.log("****"+JSON.stringify(json)));
}
catch(err) {
console.error("999999999"+err);
}
console.log("Here I should be able to get response of the invoked rest api");
}