# Custom Code Action Retry Mechanism Not Triggering

**URL:** <https://community.hubspot.com/t/custom-code-action-retry-mechanism-not-triggering/112172>\
**Category:** APIs & Integrations\
**Tags:** free\
**Created:** [July 17, 2024, 12:25pm UTC](https://community.hubspot.com/t/custom-code-action-retry-mechanism-not-triggering/112172 "2024-07-17T12:25:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoneebAmin](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@MoneebAmin](https://community.hubspot.com/u/MoneebAmin)\
**Post date:** [July 17, 2024, 12:25pm UTC](https://community.hubspot.com/t/custom-code-action-retry-mechanism-not-triggering/112172/1 "2024-07-17T12:25:19Z")

</div>

I am reaching out to seek your assistance with an issue I am experiencing with the retry mechanism for my custom code action in HubSpot workflows. Despite following the documented guidelines for raising exceptions to trigger retries, it appears that the retry mechanism is not being activated as expected.

Here are the details of my current implementation:

- **API Key Initialization** : I am initializing the HubSpot client using an API key retrieved from environment variables.
- **Simulated API Call** : I am making a simulated API request to [https://example.com/test-endpoint](https://example.com/test-endpoint) to test the retry mechanism.
- **Exception Handling** : I am raising exceptions for HTTP errors and request-related issues to signal HubSpot to retry the action.

Below is the core part of my code:

```lia-code-sample
import requests
import os
from hubspot import HubSpot
from requests.exceptions import HTTPError

def main(event):
 api_key = os.getenv('api_key')
 if not api_key:
 raise ValueError("api_key is missing in environment variables")

 hubspot = HubSpot(access_token=api_key)
 print(hubspot)

 url = "https://example.com/test-endpoint"

 try:
 response = requests.get(url)
 response.raise_for_status()

 return {
 "outputFields": {
 "message": "Request was successful."
 }
 }

 except HTTPError as e:
 print(f"HTTP error occurred and will trigger retry: {e}")
 raise

 except requests.exceptions.RequestException as e:
 print(f"Request error occurred: {e}")
 raise

 except Exception as e:
 print(f"An error occurred: {e}")
 raise
​

```

Despite the exceptions being raised correctly, the retry mechanism does not seem to be engaged by HubSpot. I am seeing error messages such as:

```lia-code-sample
HTTP error occurred and will trigger retry: 500 Server Error: Internal Server Error for url: https://example.com/test-endpoint
LAMBDA_WARNING: Unhandled exception.
​

```

provide guidance on what might be missing or incorrectly configured to ensure the retry mechanism works as intended?

Thank you in advance for your assistance.

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [July 18, 2024, 11:41pm UTC](https://community.hubspot.com/t/custom-code-action-retry-mechanism-not-triggering/112172/2 "2024-07-18T23:41:04Z")

</div>

Hi, @MoneebAmin 👋 Thanks for including your details. We’re you able to make any progress with your issue? — Jaycee

---

<div class="post-metadata">

**Author:** ![emiliano\_earth](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/emiliano_earth/32/204052_2.png) [@emiliano\_earth](https://community.hubspot.com/u/emiliano_earth)\
**Post date:** [February 11, 2025, 3:09pm UTC](https://community.hubspot.com/t/custom-code-action-retry-mechanism-not-triggering/112172/3 "2025-02-11T15:09:39Z")

</div>

Hi @MoneebAmin,

Any luck resolving this? I’m facing the same issue. [According to the documentation](https://developers.hubspot.com/docs/reference/api/automation/custom-code-actions#retries:~:text=If%20you%27re%20using%20Python%20and%20encounter%20a%20rate%20limiting%20error%20but%20you%20want%20HubSpot%20to%20retry%20your%20call%2C%20you%27ll%20need%20to%20raise%20the%20error%20in%20the%20except%20block%20of%20your%20custom%20code%20action.), simply raising an exception should prompt HubSpot to retry after a few hours, but that doesn’t seem to be working as expected. I’m a bit confused about this.
