Hello everyone,
I have this script that copies a file in Company Home and throws and exception after the copy throws and exception.
function main(){
try{
var node = utils.getNodeFromString("workspace://SpacesStore/c9a77e78-2034-46ec-ae36-48049ee088d7");
var nn = node.copy(companyhome);
throw "exception";
}catch(e){
print(e.stack);
status.setCode(status.STATUS_NOT_FOUND, e);
return null;
}
}
main();
I set the level of transaction to required, but the file is copied anyways.
I have three questions:
Ludovico
Solved! Go to Solution.
You are throwing a JavaScript tier exception which is handled in the same script that it is thrown in. Alfresco will only deal with any exceptions that cross an API boundary or bubble up to the top-level web script call. Since you are explicitely handling the exception without rethrowing it, there is no way for the retry logic to even be aware of the exception and handle it. By handling it yourself you are specifically saying "I got this - no need to run the default rollback".
If you want Alfresco to rollback the transaction, just make sure that any exceptions are propagated properly up the call chain. If you want a specific status code and message to be set, you'd have to use the Java WebScriptException class to tell the default handling what it should set in the response.
You are throwing a JavaScript tier exception which is handled in the same script that it is thrown in. Alfresco will only deal with any exceptions that cross an API boundary or bubble up to the top-level web script call. Since you are explicitely handling the exception without rethrowing it, there is no way for the retry logic to even be aware of the exception and handle it. By handling it yourself you are specifically saying "I got this - no need to run the default rollback".
If you want Alfresco to rollback the transaction, just make sure that any exceptions are propagated properly up the call chain. If you want a specific status code and message to be set, you'd have to use the Java WebScriptException class to tell the default handling what it should set in the response.
Thank you very much for the explanation!
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.