When using transactional webscripts (defined as <transaction>required</transaction>) we need sometimes (in case of managed critical errors) to cancel/rollback the transaction and return a customized error notification to the client. So far, the only way we have found to indicate the Alfresco/Spring WebScript framework to interrupt and rollback the transaction is to stop the script execution by throwing out an exception. This way, the framework will:
- cancel/rollback the transaction (no data commited in DB as expected)
- return a typical error 500 (status.code = 500, usual error notification with stack trace...)
But, we would like to better handle the returned error...
We wonder if there is another way to notify the framework to cancel/rollback the Spring transaction in order to keep full programmatic control on the returned HTTP answer returned (e.g. return an other error code like 400, return another JSON answer,...).
Setting status.code = 400 + status.redirect = true is not enough. Without throwing an exception, the framework will consider that the execution went fine and the Repository changes are committed (what we absolutely don't want if we found an error during the execution).
status.code = 400;
satus.redirect = true;
status.transactionRollback = true; // TODO add-on