Error Handling
Handle errors gracefully so tracking never breaks your form.
⏱ 3 minPrerequisites: Understand trackResponse()
Problem: If trackResponse() throws an error with no error handling, it could prevent your form from completing — which means the user sees a broken experience.
Solution: Wrap trackResponse() in a try-catch so it fails silently — EnterestOS should never break a form submission.
Recommended Pattern
typescript
const handleSubmit = async (e) => {
e.preventDefault();
// 1. Run your existing submit logic first
await submitToYourBackend(formData);
// 2. Show success to user immediately
setSubmitted(true);
// 3. Track with EnterestOS — fail silently
try {
await enterestos.trackResponse({
type: 'demo_request',
payload: formData
});
} catch (error) {
// Log for debugging — never show to user
console.error('EnterestOS tracking failed:', error);
}
};Fire-and-Forget Pattern
typescript
// Non-blocking — does not delay the user's success state
enterestos.trackResponse({
type: 'demo_request',
payload: formData
}).catch(error => {
console.error('Tracking failed:', error);
});Common Errors and Fixes
| Error | Cause | Fix |
|---|---|---|
| Project key is required | No projectKey in createEnterestOS() | Add your project key |
| Invalid project key | Key does not match any project | Check key in Inbox |
| Payload cannot be empty | payload: {} passed | Include at least one field |
| Response type is required | type field missing | Add a type string |
| Network error | API unreachable | Check connection, retry |
Result: Your form is now resilient — EnterestOS tracking failures are logged but never surface to the person submitting the form.
Common Questions
Should I block the form if EnterestOS tracking fails?
No. Always show the user a success state based on your own backend. EnterestOS is a tracking layer — if it fails, the user's submission still happened. Log the error quietly.
Next
Testing →