Skip to content

React SDK

@errpulse/react captures frontend errors, failed network requests, and React component crashes from your React application.

Installation

bash
npm install @errpulse/react

ErrPulseProvider

Wrap your app with the provider to start capturing errors:

tsx
import { ErrPulseProvider } from "@errpulse/react";

function App() {
  return (
    <ErrPulseProvider endpoint="http://localhost:3800">
      <YourApp />
    </ErrPulseProvider>
  );
}

Props Reference

PropTypeDefaultDescription
endpointstringrequiredErrPulse server URL
projectIdstringundefinedProject identifier for multi-project setups
captureConsoleErrorsbooleantrueCapture console.error calls
captureFetchbooleantrueIntercept and track fetch requests
captureXHRbooleantrueIntercept and track XMLHttpRequest calls
captureResourceErrorsbooleantrueCapture failed img/script/css loads
errorBoundaryFallbackReactNode | (error: Error) => ReactNodeundefinedFallback UI for React crashes

Full Example

tsx
<ErrPulseProvider
  endpoint="http://localhost:3800"
  projectId="my-web-app"
  captureConsoleErrors={true}
  captureFetch={true}
  captureXHR={true}
  captureResourceErrors={true}
  errorBoundaryFallback={(error) => (
    <div>
      <h2>Something went wrong</h2>
      <p>{error.message}</p>
    </div>
  )}
>
  <App />
</ErrPulseProvider>

useErrPulse Hook

Use the useErrPulse hook for manual error and message capture:

tsx
import { useErrPulse } from "@errpulse/react";

function CheckoutButton() {
  const { captureError, captureMessage } = useErrPulse();

  const handleClick = async () => {
    try {
      await processPayment();
      captureMessage("Payment successful", "info", { plan: "pro" });
    } catch (err) {
      captureError(err, { step: "payment" });
    }
  };

  return <button onClick={handleClick}>Checkout</button>;
}

captureError(error, extra?)

ts
captureError(new Error("Form validation failed"), { field: "email" });
captureError("Something went wrong"); // String also accepted

captureMessage(message, severity?, extra?)

ts
captureMessage("User clicked CTA", "info");
captureMessage("API response slow", "warning", { duration: 5200 });
captureMessage("Upload failed", "error", { fileSize: "50MB" });

Error Boundary

The ErrPulseProvider includes a built-in error boundary. When a React component crashes, it:

  1. Captures the error with full stack trace and component stack
  2. Reports it to the ErrPulse server
  3. Renders the errorBoundaryFallback if provided, or nothing

You can also use the error boundary component directly:

tsx
import { ErrPulseErrorBoundary } from "@errpulse/react";

function App() {
  return (
    <ErrPulseErrorBoundary fallback={<p>Something broke</p>}>
      <RiskyComponent />
    </ErrPulseErrorBoundary>
  );
}

What Gets Captured

The SDK installs the following instruments automatically:

InstrumentWhat It CapturesHow
Global error handlerJavaScript runtime errorswindow.onerror
Rejection handlerUnhandled promise rejectionswindow.onunhandledrejection
Fetch interceptorFailed/errored fetch requestsMonkey-patches window.fetch
XHR interceptorFailed/errored XHR requestsMonkey-patches XMLHttpRequest
Console interceptorconsole.error callsWraps console.error
Resource error handlerFailed img/script/css loadsCapture-phase event listener
Error boundaryReact component crashesReact error boundary

Correlation ID

The React SDK automatically injects an X-ErrPulse-Correlation-ID header into every outgoing fetch request. This links frontend requests to backend errors:

Frontend: fetch("/api/checkout")
  → Header: X-ErrPulse-Correlation-ID: a1b2c3d4e5f6

Backend: expressRequestHandler() reads the header
  → If an error occurs, both the request and error share the same correlation ID

Dashboard: Shows the full chain from user action → request → error

This happens automatically when both @errpulse/node and @errpulse/react are installed. No configuration required.

Page Unload

The SDK uses navigator.sendBeacon() on page unload to flush any remaining buffered events. This ensures errors captured right before the user navigates away are still delivered to the server.

Released under the MIT License.