UserInfoEnhancer
File: user-info.enhancer.ts
Overview
The UserInfoEnhancer
class extends error objects with user-related metadata, providing essential context for debugging and analytics. This includes user identification, session details, roles, and other relevant information.
Properties
user
User ID or username associated with the error, default is an empty string.
sessionId
Session ID of the user, default is an empty string.
roles
Array of roles or permissions, default is an empty array.
authToken
Authentication token, default is an empty string.
ipAddress
IP address, default is an empty string.
userAgent
Browser and OS details, default is an empty string.
actionHistory
Array of previous actions taken by the user, default is an empty array.
Methods
setUser(user: string)
setUser(user: string)
Sets the user ID or username. Validates if it's a valid string.
Usage Example:
setSessionId(sessionId: string)
setSessionId(sessionId: string)
Sets the session ID. Validates if it's a valid string.
Usage Example:
setRoles(roles: string[])
setRoles(roles: string[])
Sets the roles or permissions for the user.
Usage Example:
setAuthToken(token: string)
setAuthToken(token: string)
Sets the authentication token. Validates if it's a valid string.
Usage Example:
setIpAddress(ip: string)
setIpAddress(ip: string)
Sets the IP address. Validates if it's a valid string.
Usage Example:
setUserAgent(userAgent: string)
setUserAgent(userAgent: string)
Sets the user agent. Validates if it's a valid string.
Usage Example:
addActionToHistory(action: string)
addActionToHistory(action: string)
Adds an action to the user's action history. Validates if it's a valid string.
Usage Example:
Common Use-Cases
Debugging: Having user metadata can significantly assist in debugging issues, especially those that are user-specific.
Audit and Compliance: Record user actions and roles to meet audit requirements.