Get the status of logic apps execution

I have a requirement where a mail trigger is needed if Logic apps executions fail?

As we are aware, logic apps can fail in any step and it does not move to the next action when the previous action fails.

In this case, how do I get the status of execution and trigger a mail alert?

What we’ve done in the past is write records for each task into a SQL database and use that for statusing. You can then query the database periodically and look for error records and either reprocess them or send an email.