Handling a Custom Code if it fails

Hi,

I have built a custom code in a workflow. My goal is, if the custom code fails (a.k.a. hs_execution_state != Succeeded), I want the workflow to send a Slack notification, and then finish. If not, I want the workflow to continue its course.
Is that possible?

Hi @crossm98 :waving_hand: Thanks for your question. To check my understanding, is your goal to have a form of an If/then statement after your custom code executes? Based on the outcome? If the code fails, then send the Slack notification. Is that correct?

I looked at the documentation here, Custom code workflow actions, but didn’t find a great match for what you are describing.

Hey, @miljkovicmisa @Teun @MatthiasKunz, do you have any custom-coded thoughts or suggestions :blush: for @crossm98?

Thank you very much! — Jaycee

Hi @Jaycee_Lewis,
That’s precisely what I’m looking for. Make the custom code run. If it fails, send a slack notification and finish. If it runs correctly, continue the workflow.

Hi @crossm98 , @Jaycee_Lewis ,
easiest option I can see off the top of my head would be to include a step either in the same or in a separate code step to send a JSON payload in order to post a slack message if the original code has failed. Slack has an API so you could post a message to a channel there readily enough. You can find some support for this online: https://stackoverflow.com/questions/50187220/is-there-any-way-to-post-a-webhook-using-javascript
There might be a more elegant solution, if you manage to feed the state into an if/else branching in the workflow and then send a message and finish / continue the rest of your workflow. Use branches in workflows
Cheers,
Matthias