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.

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

ErrorCauseFix
Project key is requiredNo projectKey in createEnterestOS()Add your project key
Invalid project keyKey does not match any projectCheck key in Inbox
Payload cannot be emptypayload: {} passedInclude at least one field
Response type is requiredtype field missingAdd a type string
Network errorAPI unreachableCheck 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.