If I use wix fetch to get an image for another website in page code, I get an expected rejection of the promise, with a message explaining a CORS error.
But if I run this function in the backend, the promise never gets resolved or rejected, and also nothing is caught in the catch-clause.
export async function getImage() {
var URL = "https://www.website.com/image.jpg;
try {
fetch(URL, { "method": "get" }).then(
function onResolved(httpResponse){
console.log("response: " + JSON.stringify(httpResponse));
},
function onRejected(error){
console.log(error);
});
} //
catch (error) {
console.log("ERROR " + error);
}
}
I have also tried using await
try {
var httpResponse = await fetch(URL, { "method": "get" });
console.log("response: " + JSON.stringify(httpResponse));
} //
catch (error) {
console.log("ERROR " + error);
}
None of the console.log statements are ever shown in Site Monitoring
I do see messages after a while about a 14s WebTimeout (did you forget to resolve a Promise?)
What am I doing wrong?