Errorhandle

customClientErroHandler

Purpose

This module provides custom error and warning handlers for client-side and server-side logging, integrated with Datadog for advanced error monitoring.

Functions

1. customClientErrorHandler:

  • Purpose: Handles client-side errors and logs them to Datadog and the console.
  • Parameters:
    • error: The error object to handle (default: null).
    • severity: Error severity ('low' | 'medium' | 'high' | 'critical', default: 'low').
    • title: Title for the error message (default: "From customErrorHandler").
    • meta: Additional metadata for the error (default: null).
  • Process:
    • Logs the error to Datadog Logs and RUM if the respective services are available.
    • If appDebug is enabled in the config, logs the error to the console.

2. customClientWarningHandler:

  • Purpose: Handles client-side warnings and logs them to Datadog and the console.
  • Parameters:
    • severity: Warning severity ('low' | 'medium' | 'high' | 'critical', default: 'low').
    • title: Title for the warning message (default: "From customErrorHandler").
    • meta: Additional metadata for the warning (default: null).
  • Process:
    • Logs the warning to Datadog Logs if the respective service is available.
    • If appDebug is enabled in the config, logs the warning to the console.

3. customClientErrorHandlerAsync:

  • Purpose: Asynchronously handles client-side errors by invoking customClientErrorHandler.
  • Parameters: Same as customClientErrorHandler.
  • Process: Calls customClientErrorHandler with the same parameters.

4. customServerErrorHandler:

  • Purpose: Handles server-side errors and logs them to the console.
  • Parameters:
    • error: The error object to handle (default: null).
    • severity: Error severity ('low' | 'medium' | 'high' | 'critical', default: 'low').
    • title: Title for the error message (default: "From customServerErrorHandler").
    • meta: Additional metadata for the error (default: null).
  • Process: Logs the error to the console based on the severity.

Datadog Integeration:

  • Datadog Logs: Errors and warnings are logged to Datadog if a valid ddClientToken is available in the config.
  • Datadog RUM: Errors are added to Datadog Real User Monitoring (RUM) if the service is available.

Error Severity

  • Severity levels are defined as 'low', 'medium', 'high', and 'critical'.
  • These levels control how the errors are logged and displayed.

Usage

  • Client-side error:
customClientErrorHandler(error, 'high', 'An error occurred', { additionalInfo: 'info' });
  • Server-side error:
customServerErrorHandler(error, 'critical', 'Server failure');

Default Values

  • Default error severity is 'low' if not specified.
  • Default titles are "From customErrorHandler" for client-side errors and "From customServerErrorHandler" for server-side errors

Copyright © 2026