Error handling with updateData()

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Hey!

I'm trying to write in some error handling for the updateData() function. I found in the documentation that the method returns a jQuery deferred promise object.

I am able to get it to work for the deferred.done method when there's no error:


However, it does not seem to work for the deferred.fail method when there is an error:


Am I doing something wrong, or is there a better way to implement error handling with the updateData method?

Thanks!
Kartik
Photo of Kartik Sethuraman

Kartik Sethuraman

  • 798 Points 500 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,004 Points 20k badge 2x thumb
Hi Kartik,

The issue is actually with Salesforce's Javascript / Visualforce Remoting logic, which throws errors that are uncatchable from JavaScript if there is an exception thrown server-side. There's no easy way to catch these errors other than to intercept the unsupported, Salesforce-internal JavaScript method Visualforce.remoting.Util.error --- there's no other way that we've found to intercept these JavaScript-remoting errors client-side before they are thrown as Javascript Errors.
(Edited)
Photo of Kartik Sethuraman

Kartik Sethuraman

  • 798 Points 500 badge 2x thumb
Intercepting the Visualforce.remoting.Util.error method did the trick. Thanks!