ErrorUtils: {
    captureError(error, options?): void;
    isErrorType(error, errorType): boolean;
    validateArray(value, message?): void;
    validateArrayLength<T>(array, minLength, maxLength, message?): void;
    validateArrayNotEmpty<T>(array, message): void;
    validateBigInt(value, message?): void;
    validateBoolean(value, message?): void;
    validateCreditCard(cardNumber, message?): void;
    validateDate(date, message?): void;
    validateDateInstance(value, message?): void;
    validateDateRange(startDate, endDate, message?): void;
    validateEmail(email, message?): void;
    validateEnum<T>(value, enumObj, message?): void;
    validateFileSize(size, maxSize, message?): void;
    validateFileType(file, allowedTypes, message?): void;
    validateFunction(value, message?): void;
    validateImageDimension(width, height, maxWidth, maxHeight, message?): void;
    validateInteger(value, message?): void;
    validateIP(ip, version?, message?): void;
    validateMAC(mac, message?): void;
    validateMap(value, message?): void;
    validateNegativeNumber(value, message?): void;
    validateNonNull<T>(value, message?): asserts value is T;
    validateNonNullOrUndefined<T>(value, message?): asserts value is T;
    validateNonUndefined<T>(value, message?): asserts value is T;
    validateNull(value, message?): void;
    validateNullOrUndefined(value, message?): void;
    validateNotNull<T>(value, message): asserts value is T;
    validateNotEmpty(value, message): void;
    validateNumber(value, message?): void;
    validateObject(value, message?): void;
    validateObjectKey<T>(obj, key, message?): void;
    validatePassword(password, options?): void;
    validatePhone(phone, message?): void;
    validatePositiveNumber(value, message?): void;
    validatePostalCode(postalCode, country?, message?): void;
    validatePromise(value, message?): void;
    validateRange(value, min, max, message): void;
    validateRegex(value, regex, message): void;
    validateRegExp(value, message?): void;
    validateSet(value, message?): void;
    validateSSN(ssn, message?): void;
    validateString(value, message?): void;
    validateSymbol(value, message?): void;
    validateTime(time, format?, message?): void;
    validateUndefined(value, message?): void;
    validateUrl(url, message?): void;
    validateUUID(uuid, version?, message?): void;
    validateWeakMap(value, message?): void;
    validateWeakSet(value, message?): void;
    withAsyncErrorHandling<T>(fn, errorHandler): ((...args) => Promise<Awaited<ReturnType<T>>>);
    withErrorHandling<T>(fn, errorHandler): ((...args) => ReturnType<T>);
} = ...

Utility object containing error handling and validation functions.

Type declaration

  • captureError:function
    • Captures and reports an error to DataDog.

      Parameters

      • error: unknown

        The error to capture and report

      • options: {
            log?: boolean;
            tags?: Record<string, string>;
            context?: Record<string, unknown>;
        } = {}

        Options for error capture

        • Optional log?: boolean

          Whether to log the error to console (default: true)

        • Optional tags?: Record<string, string>

          Additional tags to add to the error in DataDog

        • Optional context?: Record<string, unknown>

          Additional context to add to the error in DataDog

      Returns void

      Example

      try {
      // Some risky operation
      } catch (error) {
      ErrorUtils.captureError(error, {
      tags: { component: 'UserService' },
      context: { userId: '123' }
      });
      }
  • isErrorType:function
    • Checks if an error is a specific type of error.

      Parameters

      • error: unknown

        The error to check

      • errorType: (new (message) => Error)

        The type of error to check against

          • new (message): Error
          • Parameters

            • message: string

            Returns Error

      Returns boolean

      True if the error is of the specified type

      Example

      const isAuthError = ErrorUtils.isErrorType(error, AuthenticationError);
      
  • validateArray:function
    • Validates that a value is a valid array

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid array"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid array

  • validateArrayLength:function
    • Validates that a value is a valid array length

      Type Parameters

      • T

      Parameters

      • array: T[]

        Array to validate

      • minLength: number

        Minimum length

      • maxLength: number

        Maximum length

      • message: string = "Invalid array length"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if array length is invalid

  • validateArrayNotEmpty:function
    • Validates that an array is not empty

      Type Parameters

      • T

      Parameters

      • array: T[]

        Array to validate

      • message: string

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if array is empty

  • validateBigInt:function
    • Validates that a value is a valid bigint

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid bigint"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid bigint

  • validateBoolean:function
    • Validates that a value is a valid boolean

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid boolean value"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid boolean

  • validateCreditCard:function
    • Validates that a value is a valid credit card number

      Parameters

      • cardNumber: string

        Credit card number to validate

      • message: string = "Invalid credit card number"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if credit card number is invalid

  • validateDate:function
    • Validates that a value is a valid date

      Parameters

      • date: string | Date

        Date to validate

      • message: string = "Invalid date"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if date is invalid

  • validateDateInstance:function
    • Validates that a value is a valid date instance

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid date"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid date instance

  • validateDateRange:function
    • Validates that a value is a valid date range

      Parameters

      • startDate: string | Date

        Start date

      • endDate: string | Date

        End date

      • message: string = "Invalid date range"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if date range is invalid

  • validateEmail:function
    • Validates that a value is a valid email address

      Parameters

      • email: string

        Email address to validate

      • message: string = "Invalid email address"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if email is invalid

  • validateEnum:function
    • Validates that a value is a valid enum value

      Type Parameters

      • T extends {
            [key: string]: string | number;
        }

      Parameters

      • value: string | number

        Value to validate

      • enumObj: T

        Enum object to validate against

      • message: string = "Invalid enum value"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid enum value

  • validateFileSize:function
    • Validates that a value is a valid file size

      Parameters

      • size: number

        File size in bytes

      • maxSize: number

        Maximum file size in bytes

      • message: string = "File size exceeds maximum allowed size"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if file size is invalid

  • validateFileType:function
    • Validates that a value is a valid file type

      Parameters

      • file: File

        File to validate

      • allowedTypes: string[]

        Array of allowed MIME types

      • message: string = "Invalid file type"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if file type is invalid

  • validateFunction:function
    • Validates that a value is a valid function

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid function"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid function

  • validateImageDimension:function
    • Validates that a value is a valid image dimension

      Parameters

      • width: number

        Image width

      • height: number

        Image height

      • maxWidth: number

        Maximum width

      • maxHeight: number

        Maximum height

      • message: string = "Invalid image dimension"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if image dimension is invalid

  • validateInteger:function
    • Validates that a value is a valid integer

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid integer"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid integer

  • validateIP:function
    • Validates that a value is a valid IP address

      Parameters

      • ip: string

        IP address to validate

      • version: 4 | 6 = 4

        IP version (4 or 6)

      • message: string = "Invalid IP address"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if IP address is invalid

  • validateMAC:function
    • Validates that a value is a valid MAC address

      Parameters

      • mac: string

        MAC address to validate

      • message: string = "Invalid MAC address"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if MAC address is invalid

  • validateMap:function
    • Validates that a value is a valid map

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid map"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid map

  • validateNegativeNumber:function
    • Validates that a value is a valid negative number

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid negative number"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid negative number

  • validateNonNull:function
    • Validates that a value is a valid non-null

      Type Parameters

      • T

      Parameters

      • value: null | T

        Value to validate

      • message: string = "Value must not be null"

        Error message to throw if validation fails

      Returns asserts value is T

      Throws

      ValidationError if value is null

  • validateNonNullOrUndefined:function
    • Validates that a value is a valid non-null and non-undefined

      Type Parameters

      • T

      Parameters

      • value: undefined | null | T

        Value to validate

      • message: string = "Value must not be null or undefined"

        Error message to throw if validation fails

      Returns asserts value is T

      Throws

      ValidationError if value is null or undefined

  • validateNonUndefined:function
    • Validates that a value is a valid non-undefined

      Type Parameters

      • T

      Parameters

      • value: undefined | T

        Value to validate

      • message: string = "Value must not be undefined"

        Error message to throw if validation fails

      Returns asserts value is T

      Throws

      ValidationError if value is undefined

  • validateNull:function
    • Validates that a value is a valid null

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Value must be null"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not null

  • validateNullOrUndefined:function
    • Validates that a value is a valid null or undefined

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Value must be null or undefined"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not null or undefined

  • validateNotNull:function
    • Validates that a value is not null or undefined

      Type Parameters

      • T

      Parameters

      • value: undefined | null | T

        Value to validate

      • message: string

        Error message to throw if validation fails

      Returns asserts value is T

      Throws

      ValidationError if value is null or undefined

  • validateNotEmpty:function
    • Validates that a string is not empty

      Parameters

      • value: string

        String to validate

      • message: string

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if string is empty

  • validateNumber:function
    • Validates that a value is a valid number

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid number"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid number

  • validateObject:function
    • Validates that a value is a valid object

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid object"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid object

  • validateObjectKey:function
    • Validates that a value is a valid object key

      Type Parameters

      • T extends object

      Parameters

      • obj: T

        Object to validate

      • key: keyof T

        Key to validate

      • message: string = "Invalid object key"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if object key is invalid

  • validatePassword:function
    • Validates that a value is a valid password

      Parameters

      • password: string

        Password to validate

      • options: {
            minLength?: number;
            requireUppercase?: boolean;
            requireLowercase?: boolean;
            requireNumber?: boolean;
            requireSpecialChar?: boolean;
            message?: string;
        } = {}

        Password validation options

        • Optional minLength?: number
        • Optional requireUppercase?: boolean
        • Optional requireLowercase?: boolean
        • Optional requireNumber?: boolean
        • Optional requireSpecialChar?: boolean
        • Optional message?: string

      Returns void

      Throws

      ValidationError if password doesn't meet requirements

  • validatePhone:function
    • Validates that a value is a valid phone number

      Parameters

      • phone: string

        Phone number to validate

      • message: string = "Invalid phone number"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if phone number is invalid

  • validatePositiveNumber:function
    • Validates that a value is a valid positive number

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid positive number"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid positive number

  • validatePostalCode:function
    • Validates that a value is a valid postal code

      Parameters

      • postalCode: string

        Postal code to validate

      • country: "US" | "CA" | "UK" = "US"

        Country code for postal code format

      • message: string = "Invalid postal code"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if postal code is invalid

  • validatePromise:function
    • Validates that a value is a valid promise

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid promise"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid promise

  • validateRange:function
    • Validates that a number is within a range

      Parameters

      • value: number

        Number to validate

      • min: number

        Minimum value (inclusive)

      • max: number

        Maximum value (inclusive)

      • message: string

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if number is outside range

  • validateRegex:function
    • Validates that a value matches a regular expression

      Parameters

      • value: string

        String to validate

      • regex: RegExp

        Regular expression to match against

      • message: string

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value doesn't match regex

  • validateRegExp:function
    • Validates that a value is a valid regular expression

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid regular expression"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid regular expression

  • validateSet:function
    • Validates that a value is a valid set

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid set"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid set

  • validateSSN:function
    • Validates that a value is a valid social security number

      Parameters

      • ssn: string

        Social security number to validate

      • message: string = "Invalid SSN"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if SSN is invalid

  • validateString:function
    • Validates that a value is a valid string

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid string"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid string

  • validateSymbol:function
    • Validates that a value is a valid symbol

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid symbol"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid symbol

  • validateTime:function
    • Validates that a value is a valid time string

      Parameters

      • time: string

        Time string to validate

      • format: "12h" | "24h" = "24h"

        Time format (12h or 24h)

      • message: string = "Invalid time"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if time string is invalid

  • validateUndefined:function
    • Validates that a value is a valid undefined

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Value must be undefined"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not undefined

  • validateUrl:function
    • Validates that a value is a valid URL

      Parameters

      • url: string

        URL to validate

      • message: string = "Invalid URL"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if URL is invalid

  • validateUUID:function
    • Validates that a value is a valid UUID

      Parameters

      • uuid: string

        UUID to validate

      • version: 1 | 2 | 3 | 4 | 5 = 4

        UUID version (1-5)

      • message: string = "Invalid UUID"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if UUID is invalid

      Example

      // Validate a random UUID (version 4)
      ErrorUtils.validateUUID('123e4567-e89b-12d3-a456-426614174000', 4);

      // Validate a time-based UUID (version 1)
      ErrorUtils.validateUUID('123e4567-e89b-12d3-a456-426614174000', 1);
  • validateWeakMap:function
    • Validates that a value is a valid weak map

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid weak map"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid weak map

  • validateWeakSet:function
    • Validates that a value is a valid weak set

      Parameters

      • value: unknown

        Value to validate

      • message: string = "Invalid weak set"

        Error message to throw if validation fails

      Returns void

      Throws

      ValidationError if value is not a valid weak set

  • withAsyncErrorHandling:function
    • Wraps an async function with error handling

      Type Parameters

      • T extends ((...args) => Promise<any>)

      Parameters

      • fn: T

        Async function to wrap

      • errorHandler: ((error) => void)

        Function to handle errors

          • (error): void
          • Parameters

            • error: unknown

            Returns void

      Returns ((...args) => Promise<Awaited<ReturnType<T>>>)

      Wrapped async function

        • (...args): Promise<Awaited<ReturnType<T>>>
        • Parameters

          • Rest ...args: Parameters<T>

          Returns Promise<Awaited<ReturnType<T>>>

  • withErrorHandling:function
    • Wraps a function with error handling

      Type Parameters

      • T extends ((...args) => any)

      Parameters

      • fn: T

        Function to wrap

      • errorHandler: ((error) => void)

        Function to handle errors

          • (error): void
          • Parameters

            • error: unknown

            Returns void

      Returns ((...args) => ReturnType<T>)

      Wrapped function

        • (...args): ReturnType<T>
        • Parameters

          • Rest ...args: Parameters<T>

          Returns ReturnType<T>