03-30-2018 03:49 AM
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
03-30-2018 06:48 AM
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.
03-30-2018 05:35 AM
03-30-2018 06:48 AM
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.
03-30-2018 10:20 AM
Thank you very much for the explanation!
Explore our Alfresco products with the links below. Use labels to filter content by product module.