AnsweredAssumed Answered

Share failure message

Question asked by sans on Jul 18, 2011
Latest reply on Jul 18, 2011 by sans
Hi,
I have developed a java based webscript to subscribe to a document or a folder.
here is the subscribe-action.min.js
Alfresco.DocumentList.prototype.onActionSubscribe = function DL_onActionSubscribe(file)
   {
      var failureMessage;
      var failureHandler = function crest_failureHandler(oResponse)
        {
           //destroyLoaderMessage();
           // Clear out deferred functions
           //this.afterDocListUpdate = [];
         
         var json ={};
         
         if (oResponse.json)
            {
            json = oResponse.json;
            //console.log("code "+json.status.code);
            //console.log("json message "+json.message);
            var status = json.status.code;
            
                 if (status == 500)
                 {
                    console.log("status "+status+file.displayName);
                    failureMessage = this.msg("message.subscribe.already", file.displayName);
                 }
                 else
                 {
                    console.log("status "+status);
                    failureMessage = this.msg("message.subscribe.failure", file.displayName);
                 }
                 console.log("failureMessage "+failureMessage);
            }
        };
        this.modules.actions.genericAction(
        {
           success:
           {
              message: this.msg("message.subscribe.success", file.displayName)
           },
           failure:
           {
              callback:
              {
                 fn: failureHandler,
                 scope: this
              },
              message: failureMessage
           },
           webscript:
           {
              name: "subscribe/site/{site}/{container}",
              method: Alfresco.util.Ajax.GET
           },
           params:
           {
              site: this.options.siteId,
              container: this.options.containerId
           },
           config:
           {
              requestContentType: Alfresco.util.Ajax.JSON,
              dataObj:
              {
                 nodeRefs: [file.nodeRef]
              }
           }
        });
      };
})();
Now based on the status code I want to display different error messages.
If status code is 500 then display 'Resource is already subscribed' otherwise display 'Can not subscribe to this resource'.
My present code displays only one message irrespective of the error code/status code.
Any idea how can I pass the failureMessage from the callback function back to calling function?

Thanks
sans!!!

Outcomes