Salesforce Commerce Cloud Question 2

How can you handle service call exceptions?

a. Implement parseException method in ServiceCallBack
b. Add try-catch block in parseResponse method in ServiceCallBack
c. Call .setThrowOnError when calling the service to throw a Javascript error if the result status is not OK
d. Service call doesn’t throw exceptions by default if you don’t enable exception breaker on service profile config.

The correct answer is option C.
parseResponse method in ServiceCallBack is the method which get’s called when the service send response.
We can easily put try catch in that and handle exception.

parseResponse: function (svc, httpClient) {
        var result;
        try {
            result = JSON.parse(httpClient.text);
        } catch (e) {
            result = httpClient.text;
        return result;

About option A) There is no such method

About option C) There is no such method

About option D) The statement is not true, first there is no such option in Service Profile. And every service call can throw exception.

Leave a Reply