Get data from promise

I have a Backend file which is called from the client js code (on button click).
I am calling a remote server for data. There are 4 calls, each is called with data received on the previous call.
For that I am using promises. BUT I have a general url_call function which supposed to take care of all errors (with catch) and return the data when resolved.
This is the url_call function:
function callUrl(url_str) {

**return**  fetch(url_str, { "method" :  "get" }) 
 		.then( (httpResponse) => { 
		**if**  (httpResponse.ok) { 
			 **return**  Promise.resolve(httpResponse.json()); 
    			 }  **else**  { 
			**return**  Promise.reject( "Fetch did not succeed" ); 
     		} 
 } ) 
 .then(json => log (json)) 
 . **catch** (err => log(err)); 

} 

This url_call function is called 4 times from a main function in the backend js file.
log - loggs the data sent to a db file with wix-inserts. I see the correct data of the log(json) command.
I thought or hoped that I would see the data back from the callUrl function because I am using a return on the fetch call. But I get an object-promise.
How do I get that json back in the function who called the callUrl function.
Thanks

What is this l og (json) ? I don’t see any log function here. Can you let us know what this log() function does.

log - loggs the data sent to a db file with wix-insert.

function log(text){

wixData.insert( "log" , {title: text}); 

}

This is where I see the data. BUT returning to the function which called the function callUrl, I see an [object Promise], and I am looking for the data “inside”. Thanks

Try:

import {fetch} from ‘wix-fetch’;
// …
function callUrl(url_str) {
return fetch(url_str, {“method”: “get”})
.then(httpResponse => {
if(!httpResponse.ok){return Promise.reject(“Fetch did not succeed”);}
return httpResponse.json();
} )
.then(json => log (json))
.catch(err => log(err));
}

Thanks but I still do not see any data. I don’t even see the data I logged in my original code.

I get a
{
“errorGroup”: “User”
}

I saw in the docs that this can come from credentials issue. Not the case here as I log the data OK in the code I sent. I just need to return that data to the calling function.
Thanks Elisheva

It’s not so clear what you’re trying to do and what fails.
I see in your code that your’e trying to insert a new record to your collection.
Is that what you’re trying to do? Does it fail?
What’s happening if you add:

 .then(async json => { await log(json); return json; })

Is that what you were trying to do?

kind of
I manages with a workaround. Create a chain of promise calls from the front end js file. Instead of one call from the front end file and have the chain of promises at the backend js file.
Thanks