Hello,
I have an issue when I try to insert an item to a database using code.
I get this error on the live site: Error: Unable to handle the request. Contact the site administrator or view site monitoring logs for more information.
And this error on Preview: Request failed with status code 400
Permissions look all good, they are set to anyone.
Any idea what’s causing this?
@yisrael-wix
@yisrael-wix Really need some help on this one as users are reporting not being able to submit reviews…
@russian-dima Thanks for your help, but sadly no, that does not help. I have already set all the dataset permission to anyone.
More information is required. Please share your code in a code block. What does the DB collection look like?
@yisrael-wix
Here my page code:
export function submitButton_click(event) {
$w('#errorMessage').hide
console.log("Submit button was clicked")
var swear_words_arr=new Array("badword1","badword2","badword3", "badword4");
var regex = new RegExp('\\b(' + swear_words_arr.join('|') + ')\\b', 'i' );
var text = $w('#textBox1').value;
if(regex.test(text)) {
$w('#errorMessage').text = "ERROR: Please make sure your review has no profane, racist or homophobic text, then try again"
$w('#errorMessage').show();
console.log("ERROR: Please make sure your review has no profane, racist or homophobic text, then try again")
$w('#textBox1').focus();
return false;
// This part is working fine, it is just below this that is not working good
} else {
let rememberMe = local.getItem("rememberMe")
if (rememberMe === "true") {
var _id = local.getItem("_id");
var username = local.getItem("username");
} else {
var username = session.getItem("username");
var _id = session.getItem("_id");
var usernameURL = "/members/update/" + _id
}
let submitRequestData = {
"token": ("#captcha").token,
"data": {
"review": $w("#textBox1").value,
"starRating": $w("#text136").text,
"restaurantName": $w("#text151").text,
"personName": username,
"usernameURL": usernameURL
}
}
processSubmission(submitRequestData)
.then( () => {
$w("#captcha").reset();
$w("#submitButton").disable();
$w("#errorMessage").text = "Review successfully submitted!";
$w("#errorMessage").show();
})
.catch( (err) => {
var errorMsg = err.message;
var errCode = err.code;
console.log(errorMsg)
console.log(errCode)
$w("#captcha").reset();
$w("#submitButton").disable();
$w("#errorMessage").text = "Something went wrong. Please redo the captcha challenge.";
// I am getting this error in the text element
$w("#errorMessage").show();
})
console.log("That review is not profane");
}
}
Backend code:
import wixCaptcha from 'wix-captcha-backend';
import wixData from 'wix-data';
export function processSubmission(submitRequestData) {
return wixCaptcha.authorize(submitRequestData.token)
.then(() => {
return wixData.insert("Reviews", submitRequestData.data);
});
}
And here’s what my collection looks like:
All the field ID’s match the code
Thanks,
Alex
@alexobc The code itself looks OK at a glance, however I might be missing something.
It seems to me that the error is from the call to wixCaptchaBackend.authorize() . You’ll need to debug your code to find out what’s wrong with the way you’re calling it.
@yisrael-wix
How do you recommend debugging it, the only methods I really know are console.log and live site monitoring, do you have any advice?
I recently started seeing this error despite not making any changes to my code… and the occurrences are seemingly random. After running the same exact sequence of actions several times, I was able to recreate the error twice. Some insights into why this happens and how to avoid it would be very helpful as I can’t launch my site without proper handling