# Troubleshooting & Error Handling

#### Global JavaScript Error Handler

Add a global error handler to catch widget errors in the browser:

```javascript
<script>
window.onerror = function(msg, url, line, col, error) {
    console.error('Widget error:', { msg, url, line, col, error });
    return false;
};
</script>
```

#### React Error Boundary Example

For React apps, use an error boundary to catch integration errors:

```typescript
import React from 'react';

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }
  static getDerivedStateFromError(error) {
    return { hasError: true };
  }
  componentDidCatch(error, errorInfo) {
    console.error('Widget integration error:', error, errorInfo);
  }
  render() {
    if (this.state.hasError) {
      return <h2>Something went wrong loading the widget.</h2>;
    }
    return this.props.children;
  }
}
```

#### Common Issues & Solutions

* **Widget not loading:** Check browser console for errors. Ensure the script URL and Site ID are correct.
* **Subscription ID not found:** Make sure your backend is passing the correct Stripe subscription ID to the frontend.
* **API errors:** Check your server logs for error messages. Ensure your API keys and environment variables are set correctly.
* **Widget not appearing:** Make sure the script is included after the DOM is loaded, and there are no JavaScript errors on the page.

If you encounter persistent issues, check your server logs and browser console, and contact support with error details.

### Need Help?

If you encounter any issues with the integration, please contact our support team.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://staysignal.gitbook.io/staysignal-docs/integration-guides/troubleshooting-and-error-handling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
