cancel
Showing results for 
Search instead for 
Did you mean: 

Share failure message

sans
Champ in-the-making
Champ in-the-making
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!!!
2 REPLIES 2

mikeh
Star Contributor
Star Contributor
Any idea how can I pass the failureMessage from the callback function back to calling function?
You can't directly, because the network call is asynchronous. Either create a new function that the failure handler calls with the reponse, or handle the message display in the failure handler itself.

Thanks,
Mike

sans
Champ in-the-making
Champ in-the-making
Mike,
Thanks for the quick response.
Yes. I handled the message display in the failure handler and it's working.

Thanks!!!
Sanjay.