How to only run a poststop lifecycle task if main task hasn't failed

I see that there’s a poststop task you can run but it runs even if the main task fails. Is there any way to run a poststop task only if the main task doesn’t fail? Thanks!