# Catching errors with Forms API

**URL:** <https://community.hubspot.com/t/catching-errors-with-forms-api/78877>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [April 6, 2023, 6:58pm UTC](https://community.hubspot.com/t/catching-errors-with-forms-api/78877 "2023-04-06T18:58:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guru](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/guru/32/100617_2.png) [@Guru](https://community.hubspot.com/u/Guru)\
**Post date:** [April 6, 2023, 6:58pm UTC](https://community.hubspot.com/t/catching-errors-with-forms-api/78877/1 "2023-04-06T18:58:50Z")

</div>

I’m creating a form on an external site using the normal **hbspt.forms.create()** function. I’d like to send errors to a Slack channel via webhook, but I don’t see a way to actually catch the errors with this method of form submission. The current workaround would be to **preventDefault()** in the **onFormSubmit** callback and use my own ajax call to the api, but that doesn’t seem like it should be the path forward. Thoughts?

---

<div class="post-metadata">

**Author:** ![Syeda\_Fatima](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/syeda_fatima/32/36951_2.png) [@Syeda\_Fatima](https://community.hubspot.com/u/Syeda_Fatima)\
**Post date:** [April 7, 2023, 5:54am UTC](https://community.hubspot.com/t/catching-errors-with-forms-api/78877/2 "2023-04-07T05:54:31Z")

</div>

Hey @Guru,

I would like to suggest, one approach that you could take is to use the onFormReady callback function to add a custom error handler to the form submission.

Here’s an example implementation:

hbspt.forms.create({  
// your form settings here  
onFormReady: function($form) {  
$form.on(‘submit’, function(event) {  
// prevent the default form submission behavior  
event.preventDefault();

// perform your own form submission using AJAX  
$.ajax({  
url: ‘your-form-endpoint-url’,  
type: ‘POST’,  
data: $form.serialize(),  
success: function(response) {  
// handle success case  
},  
error: function(xhr, status, error) {  
// send the error to your Slack channel via webhook  
$.post(‘your-slack-webhook-url’, {  
text: 'Form submission error: ’ + error  
});  
}  
});  
});  
}  
});

With this approach, you’re still able to use the hbspt.forms.create() method to generate your form, but you’re intercepting the form submission event to handle errors in your own custom way. In this example, errors are sent to a Slack channel via a webhook.

And please note that this is just one approach, and depending on your specific use case and requirements, there may be other ways to handle errors with the HubSpot Forms API.

Hope this helps! Cheers.

---

<div class="post-metadata">

**Author:** ![Guru](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/guru/32/100617_2.png) [@Guru](https://community.hubspot.com/u/Guru)\
**Post date:** [April 7, 2023, 5:16pm UTC](https://community.hubspot.com/t/catching-errors-with-forms-api/78877/3 "2023-04-07T17:16:35Z")

</div>

Hi [@Syeda\_Fatima](https://community.hubspot.com/t5/user/viewprofilepage/user-id/114957), thanks for the tip. That’s the option I was currently thinking of, but I was hoping there was a separate callback like onFormError or similar. I’ll move forward with an ajax call!

---

<div class="post-metadata">

**Author:** ![Nagarjoon](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@Nagarjoon](https://community.hubspot.com/u/Nagarjoon)\
**Post date:** [April 24, 2024, 3:15pm UTC](https://community.hubspot.com/t/catching-errors-with-forms-api/78877/4 "2024-04-24T15:15:28Z")

</div>

It sounds like you’re facing a challenge with capturing errors from form submissions made through the HubSpot Forms API and sending them to a Slack channel via webhook. While the hbspt.forms.create() function is convenient for form submission, it doesn’t provide a built-in way to catch errors directly. Your proposed workaround of using preventDefault() in the onFormSubmit callback and then making your own AJAX call to the API is a valid approach. However, if you’re looking for a more streamlined solution, you might consider implementing a custom error handling mechanism within your form submission process. This could involve listening for form submission events, capturing any errors that occur during submission, and then sending those errors to your Slack channel via webhook. By building this custom error handling logic into your form submission process, you can ensure that errors are reliably captured and communicated, providing a smoother experience for both users and administrators.
