IdentifiersEnhancer
The IdentifiersEnhancer class is a part of the error-enhanced library designed to augment error objects with unique identifiers, custom error codes, and additional metadata. This class is particularly beneficial for in-depth error analysis in large-scale applications.
Properties
id
A unique identifier (UUID) for the error object, auto-generated upon instantiation.
errorCode
A custom error code, default is -1.
errorCodePrefix
A prefix for the error code, default is an empty string.
errorDescription
A human-readable description of the error code, default is an empty string.
timestamp
A Unix timestamp representing when the error object was instantiated, default is -1.
severity
Severity level of the error, defaults to Severity.MEDIUM.
category
Category to which the error belongs, defaults to Category.UNKNOWN.
Methods
setErrorCode(errorCode: number)
setErrorCode(errorCode: number)Sets the custom error code. Validates if it's a number.
Usage Example:
const error = new IdentifiersEnhancer();
error.setErrorCode(400);setErrorCodePrefix(prefix: string)
setErrorCodePrefix(prefix: string)Sets the error code prefix. Validates if it's a valid string.
Usage Example:
error.setErrorCodePrefix("ERR");setErrorDescription(description: string)
setErrorDescription(description: string)Sets a human-readable description for the error code. Validates if it's a valid string.
Usage Example:
error.setErrorDescription("Bad Request");setSeverity(severity: Severity)
setSeverity(severity: Severity)Sets the error's severity level. Validates against the Severity enum.
Usage Example:
error.setSeverity(Severity.HIGH);setCategory(category: Category)
setCategory(category: Category)Sets the error's category. Validates against the Category enum.
Usage Example:
error.setCategory(Category.SYSTEM);getHash()
getHash()Calculates a hash value for the error object based on its properties.
Usage Example:
const hash = error.getHash();Common Use-Cases
Audit & Logging: This class is useful for attaching additional metadata to errors, aiding in more effective error tracking in logging systems.
Error Analysis: The extra information provided can be helpful for in-depth error analysis.
Last updated
Was this helpful?