Prompt

I'm building a React app and need frontend error capture

Technology / Observability1 observationLast seen Oct 20, 2026

Latest observation

Oct 20, 2026OpenAI APIWeb search: off

To capture frontend errors in a React app, you usually want three layers:

  1. Global JS errors
  2. Unhandled promise rejections
  3. React render/component errors

1) Global error capture

Add listeners in your app entry point:

window.addEventListener("error", (event) => {
  console.error("Global error:", event.error || event.message);
  // send to your logging service here
});

window.addEventListener("unhandledrejection", (event) => {
  console.error("Unhandled promise rejection:", event.reason);
  // send to your logging service here
});

2) React Error Boundary

Error boundaries catch errors during rendering, lifecycle methods, and constructors of child components.

import React from "react";

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false, error: null };
  }

  static getDerivedStateFromError(error) {
    return { hasError: true };
  }

  componentDidCatch(error, info) {
    console.error("React error boundary caught:", error, info);
    // send to your logging service here
  }

  render() {
    if (this.state.hasError) {
      return <h1>Something went wrong.</h1>;
    }

    return this.props.children;
  }
}

export default ErrorBoundary;

Use it near the top of your component tree:

<ErrorBoundary>
  <App />
</ErrorBoundary>

3) Optional: route-level and API error handling

If you use fetch/axios, wrap calls and log failures:

async function loadData() {
  try {
    const res = await fetch("/api/data");
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    return await res.json();
  } catch (err) {
    console.error("API error:", err);
    throw err;
  }
}

4) Production logging tools

Common choices:

  • Sentry
  • Bugsnag
  • Datadog RUM
  • LogRocket

Example with Sentry:

import * as Sentry from "@sentry/react";

Sentry.init({
  dsn: "YOUR_DSN",
  integrations: [
    Sentry.browserTracingIntegration(),
  ],
  tracesSampleRate: 1.0,
});

Wrap your app:

<Sentry.ErrorBoundary fallback={<p>Something went wrong.</p>}>
  <App />
</Sentry.ErrorBoundary>

Recommended setup

  • Use Error Boundary for React render errors
  • Use window error + unhandledrejection for global runtime issues
  • Use a monitoring service like Sentry for production visibility

If you want, I can give you a drop-in React error capture utility that sends errors to your backend or Sentry.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.