Course contentsShow
← Web Development
Lesson 2811 of 2,98250. Third-Party IntegrationsFree lesson

Custom Error Reporting

Use captureException and captureMessage to manually report errors, warnings, and important events.

Custom Error Reporting

What you'll learn: How to manually send specific errors, warnings, and contextual events to Sentry beyond automatic crash detection.

While Sentry automatically captures unhandled errors (as you set up previously), many important issues require manual reporting. Maybe a network request fails silently, a business-critical operation encounters an unexpected state, or you want to track user actions that led to problems—these scenarios need explicit error reporting.

The Two Core Methods

captureException(error) reports actual Error objects to Sentry. Use this when you've caught an exception in a try/catch block but still want it tracked:

try {
  await processPayment(orderData);
} catch (error) {
  // Handle gracefully for user, but still report it
  Sentry.captureException(error);
  showUserMessage("Payment failed, please try again");
}

captureMessage(message, level) sends text-based alerts without an actual Error object. Perfect for tracking warnings, business logic issues, or breadcrumbs:

if (cartTotal > userBalance) {
  Sentry.captureMessage("Insufficient funds detected", "warning");
}

// Or track important events
Sentry.captureMessage("User completed checkout without promo code", "info");

Severity Levels

The level parameter accepts: "fatal", "error", "warning", "info", or "debug". This helps you filter and prioritize issues in Sentry's dashboard.

Real-World Pattern

function validateCriticalData(data) {
  if (!data.userId) {
    Sentry.captureMessage("Missing userId in checkout flow", "error");
    return false;
  }
  return true;
}

Think of it like having a direct phone line to your monitoring system—automatic detection catches crashes, but these methods let you deliberately report "this shouldn't happen" moments before they become crashes.

Key Takeaway: Use captureException() for caught errors you still want tracked, and captureMessage() for warnings and contextual events that help diagnose issues before they escalate.