cancel
Showing results for 
Search instead for 
Did you mean: 

ResponseStatus object returned by a remote.call method

soldiertt
Champ in-the-making
Champ in-the-making
Hi,


I have a complete application based on webscripts, it is using Alfresco Share webscripts for front end calling repository webscripts.
Typical share webscript looks like :

var json = remote.call("/imaging/document/parentdoc");
if (json.status == 200) {
   //Do stuff
} else {
   logger.log("Error …..");
   //Manage error code
   json.status.message // here i want the backend message but empty :-(
}

When repo webscript looks like :

// business code
if (contentNode.typeShort == "fds:content") {
   //business code
} else {
   status.code = 400;
   status.message = "Bad request : node is not a content !";
   status.redirect = true;
}

So we are able to retrieve the return status code (400), but i would like to also retrieve the status message !!!
That would be very handy to have this message back to the front end, so we can be aware of the root cause message.

Documentation http://wiki.alfresco.com/wiki/Surf_Platform_-_Freemarker_Template_and_JavaScript_API#Response
seems to say that info is available but when in my share webscript i try :
json.status.message // it returns empty string
json.status.redirect // return false where it should be true
json.status.code // return correct response code like 'json.status'


thank you for your help
1 REPLY 1

soldiertt
Champ in-the-making
Champ in-the-making
Hey, found it !

Since my repository webscript response format is Json, even when redirecting with an error status code and message it returns json 😉
So, in my share webscript i still need to parse the response as json and i have access to the message :

var json = remote.call("/imaging/boxes/admin");
obj = eval("(" + json + ")");
if (json.status == 200) {
   model.result = obj;
} else {
   status.code = 500;
   status.message = obj.message; //GOT it !
   status.redirect = true;
}


Additional question, any recommandation to avoid the 'eval' javascript statement that is discouraged ?

Thank you.