export class SafeNSoundError extends Error { /** * @param options {SafeNSoundError} */ constructor(options) { super(); if (typeof options === 'string') { this.errCode = options; super.message = this.getDefaultMessage(); } else if (typeof options === 'object') { for (const key in options) { this[key] = options[key]; } } else { this.errCode = 'UNKNOWN_ERROR'; this.message = 'An unknown error occurred (invalid SafeNSoundError constructor options)'; } } getDefaultMessage() { switch (this.type) { case 'USER_NOT_FOUND': return 'User not found'; case 'INVALID_CREDENTIALS': return 'Invalid credentials'; case 'EMAIL_ALREADY_EXISTS': return 'Email already exists'; case 'PASSWORD_TOO_WEAK': return 'Password is too weak'; case 'TOKEN_EXPIRED': return 'Token has expired'; case 'UNAUTHORIZED': return 'Unauthorized access'; case 'UNKNOWN_ERROR': default: return 'An unknown error occurred'; } } }