# No documentation on Custom Code Error handling - hs\_execution\_state

**URL:** <https://community.hubspot.com/t/no-documentation-on-custom-code-error-handling-hs-execution-state/100621>\
**Category:** Data Hub\
**Created:** [February 21, 2024, 8:55am UTC](https://community.hubspot.com/t/no-documentation-on-custom-code-error-handling-hs-execution-state/100621 "2024-02-21T08:55:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zayne](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zayne/32/85729_2.png) [@Zayne](https://community.hubspot.com/u/Zayne)\
**Post date:** [February 21, 2024, 8:55am UTC](https://community.hubspot.com/t/no-documentation-on-custom-code-error-handling-hs-execution-state/100621/1 "2024-02-21T08:55:55Z")

</div>

I’m trying to figure out how to get custom code actions (not custom workflow actions) to change the exectution state. All custom code actions have the enumeration “hs\_execution\_state” as an output option, but I haven’t been able to find ANY documentation on this.

 ![Screenshot 2024-02-21 at 10.53.44.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/2X/8/88923f4210bfe4ced2152eb478c7150e12f9c582.jpeg)

There is the same enumeration on [custom workflow actions](https://developers.hubspot.com/docs/api/automation/custom-workflow-actions) but that doesn’t help me.  
How does one use this enumeration state to give valuable feedback in the workflow? I’ve tried setting it using the callback method, but all I get are 2 different outputs for the same variable:

 ![Screenshot 2024-02-21 at 10.55.11.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/9/f902803cc3dc8441b7a11057c5f682e94faccb7e.png)

---

<div class="post-metadata">

**Author:** ![PamCotton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pamcotton/32/47916_2.png) [@PamCotton](https://community.hubspot.com/u/PamCotton)\
**Post date:** [February 21, 2024, 10:29pm UTC](https://community.hubspot.com/t/no-documentation-on-custom-code-error-handling-hs-execution-state/100621/2 "2024-02-21T22:29:58Z")

</div>

Hey @Zayne, thank you for posting in our Community and sharing screenshots about it.

Depending on the value of “hs\_execution\_state,” you can control the flow of your workflow. For instance, if the custom code action encounters an error, you might want to trigger alternative actions or send notifications to relevant stakeholders.

I want to invite our top experts, @danmoyle, **@louischausse, @** [**John**](https://community.hubspot.com/t5/user/viewprofilepage/user-id/4468) any recommendations for **@Zayne** matter?

Thank you,

Pam

---

<div class="post-metadata">

**Author:** ![Zayne](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zayne/32/85729_2.png) [@Zayne](https://community.hubspot.com/u/Zayne)\
**Post date:** [February 22, 2024, 8:00am UTC](https://community.hubspot.com/t/no-documentation-on-custom-code-error-handling-hs-execution-state/100621/3 "2024-02-22T08:00:31Z")

</div>

Hi Pam. Yes, I’m aware that the outcome of the custom code can control the flow of the workflow after the code. What I’m struggling to find information about is

1. what causes the custom code to reach one of those states?
2. How can I coerce the custom code to reach one of those states?

I could also just set and return my own variable to control the flow, but I would like to be able to see in the workflow logs if the custom code didn’t finish successfully, and for what reason. At the moment, even if one of my custom code blocks fails to, for instance, call an API, it is always marked as successful.

---

<div class="post-metadata">

**Author:** ![Shadab\_Khan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/shadab_khan/32/12293_2.png) [@Shadab\_Khan](https://community.hubspot.com/u/Shadab_Khan)\
**Post date:** [February 22, 2024, 8:40am UTC](https://community.hubspot.com/t/no-documentation-on-custom-code-error-handling-hs-execution-state/100621/4 "2024-02-22T08:40:56Z")

</div>

I have seen the use of console.log within various areas of code blocks to trouble shoot these kinds of issues

You just need to get creative and add some texts before your log statement so you know exactly what value is out on while line of the code

---

<div class="post-metadata">

**Author:** ![louischausse](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/louischausse/32/18067_2.png) [@louischausse](https://community.hubspot.com/u/louischausse)\
**Post date:** [February 22, 2024, 4:13pm UTC](https://community.hubspot.com/t/no-documentation-on-custom-code-error-handling-hs-execution-state/100621/5 "2024-02-22T16:13:51Z")

</div>

You cannot use the value hs\_execution\_state in your code since it is outputed after the code is ran.  
hs\_execution\_state will be set to “success” if all your code run without encountering any error.  
You need to handle errors in your code with try/catch or .then/.catch.  
When you want your code to break and stop and hs\_execution\_state to be equal to “Error” you need to throw errors properly in your code with

`throw new Error('Whoops!')`

if you console.log the error, hs\_execution\_state will be set to “Success” anyway.  
A good way to handle error is to wrap you call to apis in try/catch blocks:

```lia-code-sample
try {
 //call an external api from here
 } catch (error) { // this line will catch the error if the request in the try block fails
 throw new Error(error); // this line will log the error in the console and set the hs_execution_state to "Error"
 }

```

The following would set the hs\_execution\_state to “Success” even if there was an error when executing the code:

```lia-code-sample
try {
 //call an external api from here
 } catch (error) { // this line will catch the error if the request in the try block fails
 console.log(error); // this line will log the error in the console and set the hs_execution_state to "Success" because this is just logging some text in a string even if the content of that string is in fact an error message
 }

```

Sincerely yours,  
The Wizard of Hubs 🧙‍♂️  
Don’t forget to mark my reply as a solution if you are satisfied. If not, do not hesitate to ask me anything!

---

<div class="post-metadata">

**Author:** ![Noufel](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/noufel/32/65077_2.png) [@Noufel](https://community.hubspot.com/u/Noufel)\
**Post date:** [February 14, 2025, 6:35pm UTC](https://community.hubspot.com/t/no-documentation-on-custom-code-error-handling-hs-execution-state/100621/6 "2025-02-14T18:35:20Z")

</div>

Setting hs\_execution\_state to one of the values listed in the enumeration of hs\_execution\_state on the custom code output seems to work.  
Here’s an example:

```lia-code-sample
return callback({
 outputFields: {
 hs_execution_state: "Failed, object removed from workflow"
 }
});

```

The next step in the workflow can then receive the corresponding hs\_execution\_state.
