I'm trying to use wix-dataset's onError() method and datasetError object to figure out exactly what went wrong when a form submission fails. The goal is to be able to explain the problem to the user so they know what to do about it. I looked at the datasetError documentation here:
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#DatasetError
It says that a datasetError object should contain a code and a message, both strings.
The problem is that when I actually triggered errors and looked at the contents of the resulting datasetError objects, they didn't match the documentation at all. I was able to trigger errors in three ways: by changing the database permissions so that I wasn't allowed to write to it, by failing to fill out a required field, and by cutting my Internet connection.
When I didn't have permission to make a change, the error object I got back had fields for "line", "column", "name and "code".
When I didn't fill out a required field, the error object had only a "code" field.
When I cut my Internet connection, the error object had fields for "xhr", "errorType", "line" and "column", but neither "code" nor "message"!
I'm afraid I don't have working code to share, since I haven't even been able to find the documentation I need yet, but here's the code that catches and displays the datasetError object:
$w("#dataset1").onError((operation, error) => { $w("#text17").text = JSON.stringify(error); })
The page I was testing on is https://dwbolt4.wixsite.com/sfcknox/blank-7. If you trigger an error on submission, the placeholder paragraph changes to show the contents of the datasetError object. You can trigger a validation error by leaving the text box blank or a permission error by trying to submit while not logged in.
Where can I find an accurate description of what the datasetError object contains? Ideally, I'd like to know the values that the fields can have under different circumstances, not just what fields may exist. That way I can write code that recognizes, for instance, "The code is such-and-such, which means this error comes from the user's internet connection going out" and displays a message telling the user that their connection failed, but if they fix that and try again, it should work. If there actually WERE a message field that was present every time, I could just display that to the user, but since there's not, I'm going to need to "translate", and that means I need to know what various types of errors look like.
I'm open to suggestions about not using datasets, but if you do suggest that, I'd like some advice about what to do instead. I haven't been able to find any documentation at all yet about how to deal with errors when writing to a database directly.
If still relevant, once I was given a sort of manual while studying coding in university. It had quite a detailed explanation on some peculiarities of coding process yet I think it might lack some general information. Especially there was a considerable chapter on detecting and correcting data errors yourself. I personally found it rather practicable when I had to remove errors caused by faulty processing. As far as I remember, the manual was done by one of our professors on docsie.io. I guess looking through such manual might help to find a solution as long as errors aren`t caused by human mistakes.
Hello, I know I am late, but did you find anything?