Dificulty in error handeling

So I have this validation code:

frappe.ui.form.on("Test Doc", 'validate', function(frm){
	validate = true;
	frappe.call({method:'my_app.my_app.doctype.test_doc.test_doc.go'
        }).then(r => {
			if (r.message == 1){
            validate = false;
			frappe.throw(__('This does not exist<br>New row <a href="https://www.google.com">and a link</a>!'));
			}
	});
});

and this is the go function:

@frappe.whitelist()
def go():
	try:
		d = 1/0
	except:
		return 1

Result is this:
Error message appears for a second, disappears and the form is saved.
Does this make sense?
What am I doing wrong?

1 Like

@abrefael you are using js to call a validate function written in python . you can just write a validate function inside your class doctype

1 Like

the python function is just to show an idea.
I use the python to do something a lot more complex.
I just want to control my errors.

@abrefael write a def function called def validate(self): inside your class doctype . then you can manage more complex stuff . it’s more secure and reliable .

@abrefael about your code you can try to add async:false in your call parameters .

The validation part is less problematic.
I actually more worried about the user not getting the error.