Skip to main content
The vij-sdk provides two main APIs for capturing errors and messages: captureException() for error objects and captureMessage() for custom log messages.

captureException()

Capture and send error objects to your VIJ Admin dashboard.

Basic Usage

Signature

Parameters

Error
required
The error object to capture. Can be any JavaScript Error instance or object with name, message, and stack properties.Supported Types:
  • Native JavaScript errors (Error, TypeError, ReferenceError, etc.)
  • Custom error classes extending Error
  • Objects with error-like structure
object
default:"{}"
Additional contextual information to attach to this specific error.Use Cases:
  • User information (ID, email, role)
  • Request details (URL, method, headers)
  • Application state at time of error
  • Feature or component context
Metadata is merged with global metadata from init(). Per-error metadata takes precedence.
string
default:"error"
The severity level of this error.Options:
  • "error" - Critical errors requiring immediate attention
  • "warning" - Non-critical issues that should be investigated
  • "info" - Informational logs for tracking behavior
Severity levels help you filter and prioritize errors in the dashboard.

Automatic Error Capture

The SDK automatically captures uncaught errors and unhandled promise rejections without any additional code:
Browser Events Captured:
  • window.onerror - Uncaught exceptions
  • window.onunhandledrejection - Unhandled promise rejections
While automatic capture is convenient, it’s better to explicitly catch and handle errors in production code. Use captureException() in catch blocks for better control.

Advanced Examples

Capturing with Rich Metadata

Capturing Errors in React Components

Capturing Errors in Express Middleware

captureMessage()

Capture custom log messages without an error object.

Basic Usage

Signature

Parameters

string
required
The log message to capture.Best Practices:
  • Use clear, descriptive messages
  • Include relevant details in the message or metadata
  • Keep messages concise but informative
object
default:"{}"
Additional contextual information to attach to this message.
string
default:"info"
The severity level of this message.Options:
  • "info" - Informational messages (default for captureMessage)
  • "warning" - Warning messages
  • "error" - Error messages

Use Cases

Contextual Information

Both captureException() and captureMessage() automatically collect rich contextual information:

Browser Context

Node.js Context

This context is collected automatically. You don’t need to add it manually.

Best Practices

Add contextual information that will help debug the issue:
Error: Critical issues requiring immediate attention
Warning: Issues that should be investigated but aren’t critical
Info: Tracking and informational purposes
Never log passwords, tokens, or PII without sanitization:
Avoid overwhelming your VIJ instance with duplicate errors:
Capture the error but don’t swallow it:

Integration Patterns

React Error Boundary

Vue Error Handler

Express Error Middleware

Async/Await Error Handling

Troubleshooting

Check the following:
  1. Verify init() was called before captureException()
  2. Check browser console/server logs for network errors
  3. Ensure VIJ Admin endpoint is accessible
  4. Verify batching settings aren’t delaying delivery too long
  5. Check that error object has name, message, and stack properties
Debug: Disable batching for immediate delivery
Cause: Same error being captured multiple timesSolutions:
  • Check if error is being captured in both automatic handlers and manual try/catch
  • Implement deduplication logic for recurring errors
  • Use error grouping features in VIJ Admin dashboard
Learn more about error grouping →
Issue: Custom metadata not showing in dashboardSolution: Ensure metadata is JSON-serializable

Next Steps

SDK Configuration

Learn about all available SDK configuration options

API Reference

Explore the complete SDK API documentation

Error Grouping

Understand how VIJ groups similar errors

Dashboard Features

Explore VIJ Admin dashboard features