Const
Captures and reports an error to DataDog.
The error to capture and report
Options for error capture
Optional
log?: booleanWhether 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
try {
// Some risky operation
} catch (error) {
ErrorUtils.captureError(error, {
tags: { component: 'UserService' },
context: { userId: '123' }
});
}
Checks if an error is a specific type of error.
The error to check
The type of error to check against
True if the error is of the specified type
const isAuthError = ErrorUtils.isErrorType(error, AuthenticationError);
Validates that a value is a valid array length
Array to validate
Minimum length
Maximum length
Error message to throw if validation fails
ValidationError if array length is invalid
Validates that a value is a valid credit card number
Credit card number to validate
Error message to throw if validation fails
ValidationError if credit card number is invalid
Validates that a value is a valid date range
Start date
End date
Error message to throw if validation fails
ValidationError if date range is invalid
Validates that a value is a valid enum value
Value to validate
Enum object to validate against
Error message to throw if validation fails
ValidationError if value is not a valid enum value
Validates that a value is a valid file size
File size in bytes
Maximum file size in bytes
Error message to throw if validation fails
ValidationError if file size is invalid
Validates that a value is a valid file type
File to validate
Array of allowed MIME types
Error message to throw if validation fails
ValidationError if file type is invalid
Validates that a value is a valid image dimension
Image width
Image height
Maximum width
Maximum height
Error message to throw if validation fails
ValidationError if image dimension is invalid
Validates that a value is a valid IP address
IP address to validate
IP version (4 or 6)
Error message to throw if validation fails
ValidationError if IP address is invalid
Validates that a value is a valid non-null
Value to validate
Error message to throw if validation fails
ValidationError if value is null
Validates that a value is a valid non-null and non-undefined
Value to validate
Error message to throw if validation fails
ValidationError if value is null or undefined
Validates that a value is a valid non-undefined
Value to validate
Error message to throw if validation fails
ValidationError if value is undefined
Validates that a value is a valid null or undefined
Value to validate
Error message to throw if validation fails
ValidationError if value is not null or undefined
Validates that a value is not null or undefined
Value to validate
Error message to throw if validation fails
ValidationError if value is null or undefined
Validates that a value is a valid object key
ValidationError if object key is invalid
Validates that a value is a valid password
Password to validate
Password validation options
Optional
minOptional
requireOptional
requireOptional
requireOptional
requireOptional
message?: stringValidationError if password doesn't meet requirements
Validates that a value is a valid postal code
Postal code to validate
Country code for postal code format
Error message to throw if validation fails
ValidationError if postal code is invalid
Validates that a number is within a range
Number to validate
Minimum value (inclusive)
Maximum value (inclusive)
Error message to throw if validation fails
ValidationError if number is outside range
Validates that a value matches a regular expression
String to validate
Regular expression to match against
Error message to throw if validation fails
ValidationError if value doesn't match regex
Validates that a value is a valid time string
Time string to validate
Time format (12h or 24h)
Error message to throw if validation fails
ValidationError if time string is invalid
Validates that a value is a valid UUID
UUID to validate
UUID version (1-5)
Error message to throw if validation fails
ValidationError if UUID is invalid
// 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);
Wraps an async function with error handling
Async function to wrap
Function to handle errors
Wrapped async function
Wraps a function with error handling
Function to wrap
Function to handle errors
Wrapped function
Utility object containing error handling and validation functions.