[SalesForce] javascript remoting exception handling

I am calling remote actions which call external services. These external services are called in synchronous manner using web services callout. Are there any best practices around how to handle exception scenarios like when services do not return any response.

Best Answer

The best practice for exception handling will be showing a toast or error message on time out and this can be captured on the callback

Since JavaScript remoting you can check for errors in the callback .

Visualforce.remoting.Manager.invokeAction(
                    '{!$RemoteAction.CallController.logCall
                    }'
                    function(result, event){
                        if (event.status) {

                        } else {
                            //validatorSLDSplugin.displayalert(event.message,'error');
                            //show a toast
                        }
                    }, 
                    {escape: false}
                );

Also you can set exception message from apex by throwing exception and then showing on front end via Toast .Also you can specify time out value

Related Topic