'Call a specific feature file only when there is a failure in a the current feature

I have a use case, if the feature file that is currently running has failures in it then at the end of all scenarios, it should trigger another feature. Similar to AfterFeature hook

* configure afterFeature = function(){ karate.call('after-feature.feature'); }

but the only difference here is, it should only trigger when the feature has failure scenarios and not when all scenario is success.

Is there a way I can handle this in Karate ? The only reason I cannot put this in afterFeature is because the feature does a DB call for cleanup and it takes considerably longer time which is why I want to trigger this feature file only when there is failure



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source