Search code examples
javascriptserviceliferayliferay-service-builder

Does there exist a documentation of the Javascript Liferay Service library? How is it possible to handle error cases?


Liferay provides portlet developers Javascript code, which allows to call Liferay Services. When browsing the available API methods at /api/jsonws, a Javascript snippet is provided, which shows how this method can be called:

Liferay.Service(
  '/method',
  {
    parameter: 'value'
  },
  function(obj) {
    console.log(obj);
  }
);

However, I can't find a real documentation of this feature. While this example perfectly shows how a Service method can be called, it doesn't show how one can handle error cases.

When trying to find a documentation online, I also just found examples which showed how to call an API function, but not how to handle special cases, just like the above provided code.


Solution

  • Errors can be handled following way:

        .
        .
        .
        function(message) {
            var exception = message.exception;
    
            if (!exception) {
                // Process Success
            }
            else {
                // Process Exception
            }
        }
    

    Reference: http://www.liferay.com/community/wiki/-/wiki/Main/json+service+api