Is there a way to catch a query error?

  • 1
  • Question
  • Updated 2 years ago
  • Answered
In some predictable cases, a query will fail and user friendly messages could be given to the user to correct their mistake. Is there a way to catch this error in JavaScript like the 'add-on error' action in the action framework? When doing a try catch in JavaScript snippets, the error doesn't get caught, and the jQuery promise is resolved.

I also tried subscribing to 'models.load' events but the event only fired on success of updateData()  and it seems to consider an updateData() call a success even when the query error message pops up

loaded
PUBLISHED:
at the end of a successful call to model.updateData()
https://docs.skuid.com/latest/en/skuid/api/skuid_events.html?#skuid.events.models.loaded
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb

Posted 2 years ago

  • 1
Photo of Christine Jessen

Christine Jessen

  • 670 Points 500 badge 2x thumb
Thanks for your question!  Have you tried a callback function within the updateData call?
model.updateData(function(result) {
     if (result.totalsuccess) {
          // Do something on success
     else {
          // Do something on failure 
     }
}));

Hope this helps you out!

Christine
(Edited)
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
Thanks, I hadn't tried it. I just tried it and although I'm setting the failure to do nothing, I still get the error in the screenshot below. Here's the relevant code .


        dfrd = attachmentsMod.updateData(function(result) {            
            if (!result.totalsuccess) {
            // Do nothing on fail
            }
        });
I'm returning this deferred Jquery object later on.

Here's a screenshot of the error.

Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
I ended up passing this to apex, handling it there, and working off of the returned result.