Updated the code to retry after timeout, still getting this error. Bit of a problem as I cannot query my principal DB…
import wixData from 'wix-data';
export function queryViews() {
let query = wixData.query("Activity")
.contains("AdClickOwner", "Viewed Page:")
.limit(100)
return retryQuery(query)
.then((results) => {
console.log("query complete");
if (results.items.length > 0) {
let items = results.items;
let firstItem = items[0];
console.log(firstItem);
return firstItem;
} else {
console.log("no matching items")
}
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
console.log(errorMsg);
console.log(code);
});
}
const TIMEOUT_CODE_ONE = 'WDE0028: Request timed out.'; // error message from wix server
const TIMEOUT_CODE_TWO = 'WD_REQUEST_TIMED_OUT'; // error message from wix server
const RETRY_MAX = 3;
function retryQuery(query, iteration = 0) {
return query.find()
.catch(reason => {
if (reason === TIMEOUT_CODE_ONE || reason === TIMEOUT_CODE_TWO) {
if (iteration === RETRY_MAX) {
console.log("retrying");
console.error('retried ' + RETRY_MAX + ' times and failed');
throw reason;
}
return retryQuery(query, ++iteration);
}
//Not a timeout, throw back the error
throw reason;
})
}