UNPKG

redai-automation-web-sdk

Version:

TypeScript SDK for RedAI Automation Web API - Zalo Personal automation, messaging, advanced sticker search, and bulk operations. 100% compatible with automation-web backend. v1.8.0: Added SessionProxyService for managing proxy assignments to sessions with

583 lines 31.1 kB
"use strict"; /** * Error types and codes for RedAI Automation Web SDK * Based on @warriorteam/zalo-personal SDK error handling patterns */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ZaloErrorUtils = exports.ZaloErrorContext = exports.ERROR_MESSAGES = exports.ERROR_SEVERITY = exports.ERROR_CATEGORIES = exports.ZaloErrorSeverity = exports.ZaloErrorCode = void 0; /** * Zalo API Error Codes * Based on @warriorteam/zalo-personal SDK and common API patterns */ var ZaloErrorCode; (function (ZaloErrorCode) { // Authentication & Session Errors (1000-1099) ZaloErrorCode[ZaloErrorCode["SESSION_NOT_FOUND"] = 1001] = "SESSION_NOT_FOUND"; ZaloErrorCode[ZaloErrorCode["SESSION_EXPIRED"] = 1002] = "SESSION_EXPIRED"; ZaloErrorCode[ZaloErrorCode["SESSION_INACTIVE"] = 1003] = "SESSION_INACTIVE"; ZaloErrorCode[ZaloErrorCode["INVALID_CREDENTIALS"] = 1004] = "INVALID_CREDENTIALS"; ZaloErrorCode[ZaloErrorCode["AUTHENTICATION_FAILED"] = 1005] = "AUTHENTICATION_FAILED"; ZaloErrorCode[ZaloErrorCode["SESSION_CREATION_FAILED"] = 1006] = "SESSION_CREATION_FAILED"; ZaloErrorCode[ZaloErrorCode["SESSION_VALIDATION_FAILED"] = 1007] = "SESSION_VALIDATION_FAILED"; // User Information Errors (1100-1199) ZaloErrorCode[ZaloErrorCode["USER_NOT_FOUND"] = 1101] = "USER_NOT_FOUND"; ZaloErrorCode[ZaloErrorCode["USER_ID_INVALID"] = 1102] = "USER_ID_INVALID"; ZaloErrorCode[ZaloErrorCode["USER_PROFILE_PRIVATE"] = 1103] = "USER_PROFILE_PRIVATE"; ZaloErrorCode[ZaloErrorCode["USER_BLOCKED_YOU"] = 1104] = "USER_BLOCKED_YOU"; ZaloErrorCode[ZaloErrorCode["USER_DOESNT_EXIST"] = 1105] = "USER_DOESNT_EXIST"; ZaloErrorCode[ZaloErrorCode["USER_NOT_ACCESSIBLE"] = 1106] = "USER_NOT_ACCESSIBLE"; // Friend Management Errors (1200-1299) ZaloErrorCode[ZaloErrorCode["FRIEND_REQUEST_FAILED"] = 1201] = "FRIEND_REQUEST_FAILED"; ZaloErrorCode[ZaloErrorCode["FRIEND_NOT_FOUND"] = 1202] = "FRIEND_NOT_FOUND"; ZaloErrorCode[ZaloErrorCode["ALREADY_FRIENDS"] = 1203] = "ALREADY_FRIENDS"; ZaloErrorCode[ZaloErrorCode["FRIEND_REQUEST_SENT"] = 1204] = "FRIEND_REQUEST_SENT"; ZaloErrorCode[ZaloErrorCode["CANNOT_SEND_REQUEST"] = 1205] = "CANNOT_SEND_REQUEST"; ZaloErrorCode[ZaloErrorCode["FRIEND_BLOCKED"] = 1206] = "FRIEND_BLOCKED"; ZaloErrorCode[ZaloErrorCode["CANNOT_UNFRIEND"] = 1207] = "CANNOT_UNFRIEND"; // Group Management Errors (1300-1399) ZaloErrorCode[ZaloErrorCode["GROUP_NOT_FOUND"] = 1301] = "GROUP_NOT_FOUND"; ZaloErrorCode[ZaloErrorCode["GROUP_ID_INVALID"] = 1302] = "GROUP_ID_INVALID"; ZaloErrorCode[ZaloErrorCode["NOT_GROUP_MEMBER"] = 1303] = "NOT_GROUP_MEMBER"; ZaloErrorCode[ZaloErrorCode["NOT_GROUP_ADMIN"] = 1304] = "NOT_GROUP_ADMIN"; ZaloErrorCode[ZaloErrorCode["GROUP_FULL"] = 1305] = "GROUP_FULL"; ZaloErrorCode[ZaloErrorCode["CANNOT_JOIN_GROUP"] = 1306] = "CANNOT_JOIN_GROUP"; ZaloErrorCode[ZaloErrorCode["GROUP_CREATION_FAILED"] = 1307] = "GROUP_CREATION_FAILED"; ZaloErrorCode[ZaloErrorCode["GROUP_SETTINGS_UPDATE_FAILED"] = 1308] = "GROUP_SETTINGS_UPDATE_FAILED"; // Message & Media Errors (1400-1499) ZaloErrorCode[ZaloErrorCode["MESSAGE_NOT_FOUND"] = 1401] = "MESSAGE_NOT_FOUND"; ZaloErrorCode[ZaloErrorCode["CANNOT_SEND_MESSAGE"] = 1402] = "CANNOT_SEND_MESSAGE"; ZaloErrorCode[ZaloErrorCode["MEDIA_TOO_LARGE"] = 1403] = "MEDIA_TOO_LARGE"; ZaloErrorCode[ZaloErrorCode["UNSUPPORTED_MEDIA_TYPE"] = 1404] = "UNSUPPORTED_MEDIA_TYPE"; ZaloErrorCode[ZaloErrorCode["MESSAGE_SEND_FAILED"] = 1405] = "MESSAGE_SEND_FAILED"; ZaloErrorCode[ZaloErrorCode["MESSAGE_FORWARD_FAILED"] = 1406] = "MESSAGE_FORWARD_FAILED"; ZaloErrorCode[ZaloErrorCode["REACTION_FAILED"] = 1407] = "REACTION_FAILED"; // Request Validation Errors (1500-1599) ZaloErrorCode[ZaloErrorCode["INVALID_PARAMETERS"] = 1501] = "INVALID_PARAMETERS"; ZaloErrorCode[ZaloErrorCode["MISSING_REQUIRED_FIELDS"] = 1502] = "MISSING_REQUIRED_FIELDS"; ZaloErrorCode[ZaloErrorCode["INVALID_USER_ID_FORMAT"] = 1503] = "INVALID_USER_ID_FORMAT"; ZaloErrorCode[ZaloErrorCode["INVALID_GROUP_ID_FORMAT"] = 1504] = "INVALID_GROUP_ID_FORMAT"; ZaloErrorCode[ZaloErrorCode["INVALID_MESSAGE_FORMAT"] = 1505] = "INVALID_MESSAGE_FORMAT"; ZaloErrorCode[ZaloErrorCode["BATCH_SIZE_EXCEEDED"] = 1506] = "BATCH_SIZE_EXCEEDED"; ZaloErrorCode[ZaloErrorCode["INVALID_ATTACHMENT_FORMAT"] = 1507] = "INVALID_ATTACHMENT_FORMAT"; // Rate Limiting Errors (1600-1699) ZaloErrorCode[ZaloErrorCode["RATE_LIMIT_EXCEEDED"] = 1601] = "RATE_LIMIT_EXCEEDED"; ZaloErrorCode[ZaloErrorCode["TOO_MANY_REQUESTS"] = 1602] = "TOO_MANY_REQUESTS"; ZaloErrorCode[ZaloErrorCode["TEMPORARY_BLOCK"] = 1603] = "TEMPORARY_BLOCK"; ZaloErrorCode[ZaloErrorCode["REQUEST_LIMIT_REACHED"] = 1604] = "REQUEST_LIMIT_REACHED"; ZaloErrorCode[ZaloErrorCode["SPAM_DETECTED"] = 1605] = "SPAM_DETECTED"; // Network & Connection Errors (1700-1799) ZaloErrorCode[ZaloErrorCode["NETWORK_ERROR"] = 1701] = "NETWORK_ERROR"; ZaloErrorCode[ZaloErrorCode["CONNECTION_TIMEOUT"] = 1702] = "CONNECTION_TIMEOUT"; ZaloErrorCode[ZaloErrorCode["API_UNAVAILABLE"] = 1703] = "API_UNAVAILABLE"; ZaloErrorCode[ZaloErrorCode["SERVER_ERROR"] = 1704] = "SERVER_ERROR"; ZaloErrorCode[ZaloErrorCode["CONNECTION_REFUSED"] = 1705] = "CONNECTION_REFUSED"; ZaloErrorCode[ZaloErrorCode["DNS_RESOLUTION_FAILED"] = 1706] = "DNS_RESOLUTION_FAILED"; ZaloErrorCode[ZaloErrorCode["PROXY_CONNECTION_FAILED"] = 1707] = "PROXY_CONNECTION_FAILED"; // Permission & Access Errors (1800-1899) ZaloErrorCode[ZaloErrorCode["INSUFFICIENT_PERMISSIONS"] = 1801] = "INSUFFICIENT_PERMISSIONS"; ZaloErrorCode[ZaloErrorCode["ACCESS_DENIED"] = 1802] = "ACCESS_DENIED"; ZaloErrorCode[ZaloErrorCode["ACCOUNT_SUSPENDED"] = 1803] = "ACCOUNT_SUSPENDED"; ZaloErrorCode[ZaloErrorCode["ACCOUNT_BANNED"] = 1804] = "ACCOUNT_BANNED"; ZaloErrorCode[ZaloErrorCode["DEVICE_NOT_VERIFIED"] = 1805] = "DEVICE_NOT_VERIFIED"; ZaloErrorCode[ZaloErrorCode["REGION_RESTRICTED"] = 1806] = "REGION_RESTRICTED"; ZaloErrorCode[ZaloErrorCode["AGE_RESTRICTED"] = 1807] = "AGE_RESTRICTED"; // Business Logic Errors (1900-1999) ZaloErrorCode[ZaloErrorCode["OPERATION_NOT_ALLOWED"] = 1901] = "OPERATION_NOT_ALLOWED"; ZaloErrorCode[ZaloErrorCode["FEATURE_NOT_AVAILABLE"] = 1902] = "FEATURE_NOT_AVAILABLE"; ZaloErrorCode[ZaloErrorCode["SUBSCRIPTION_REQUIRED"] = 1903] = "SUBSCRIPTION_REQUIRED"; ZaloErrorCode[ZaloErrorCode["QUOTA_EXCEEDED"] = 1904] = "QUOTA_EXCEEDED"; ZaloErrorCode[ZaloErrorCode["INVALID_OPERATION_CONTEXT"] = 1905] = "INVALID_OPERATION_CONTEXT"; // Data Processing Errors (2000-2099) ZaloErrorCode[ZaloErrorCode["DATA_PARSING_FAILED"] = 2001] = "DATA_PARSING_FAILED"; ZaloErrorCode[ZaloErrorCode["ENCRYPTION_FAILED"] = 2002] = "ENCRYPTION_FAILED"; ZaloErrorCode[ZaloErrorCode["DECRYPTION_FAILED"] = 2003] = "DECRYPTION_FAILED"; ZaloErrorCode[ZaloErrorCode["DATA_CORRUPTION"] = 2004] = "DATA_CORRUPTION"; ZaloErrorCode[ZaloErrorCode["INVALID_JSON_FORMAT"] = 2005] = "INVALID_JSON_FORMAT"; // External Service Errors (2100-2199) ZaloErrorCode[ZaloErrorCode["EXTERNAL_API_ERROR"] = 2101] = "EXTERNAL_API_ERROR"; ZaloErrorCode[ZaloErrorCode["WEBHOOK_DELIVERY_FAILED"] = 2102] = "WEBHOOK_DELIVERY_FAILED"; ZaloErrorCode[ZaloErrorCode["CALLBACK_TIMEOUT"] = 2103] = "CALLBACK_TIMEOUT"; ZaloErrorCode[ZaloErrorCode["THIRD_PARTY_SERVICE_ERROR"] = 2104] = "THIRD_PARTY_SERVICE_ERROR"; // Generic Errors (9000-9999) ZaloErrorCode[ZaloErrorCode["UNKNOWN_ERROR"] = 9000] = "UNKNOWN_ERROR"; ZaloErrorCode[ZaloErrorCode["INTERNAL_ERROR"] = 9001] = "INTERNAL_ERROR"; ZaloErrorCode[ZaloErrorCode["INVALID_RESPONSE"] = 9002] = "INVALID_RESPONSE"; ZaloErrorCode[ZaloErrorCode["UNEXPECTED_ERROR"] = 9003] = "UNEXPECTED_ERROR"; ZaloErrorCode[ZaloErrorCode["NOT_IMPLEMENTED"] = 9004] = "NOT_IMPLEMENTED"; ZaloErrorCode[ZaloErrorCode["MAINTENANCE_MODE"] = 9005] = "MAINTENANCE_MODE"; })(ZaloErrorCode || (exports.ZaloErrorCode = ZaloErrorCode = {})); /** * Zalo Error Severity Levels */ var ZaloErrorSeverity; (function (ZaloErrorSeverity) { ZaloErrorSeverity["LOW"] = "low"; ZaloErrorSeverity["MEDIUM"] = "medium"; ZaloErrorSeverity["HIGH"] = "high"; ZaloErrorSeverity["CRITICAL"] = "critical"; })(ZaloErrorSeverity || (exports.ZaloErrorSeverity = ZaloErrorSeverity = {})); /** * Error Category Mappings */ exports.ERROR_CATEGORIES = { [ZaloErrorCode.SESSION_NOT_FOUND]: 'authentication', [ZaloErrorCode.SESSION_EXPIRED]: 'authentication', [ZaloErrorCode.SESSION_INACTIVE]: 'authentication', [ZaloErrorCode.INVALID_CREDENTIALS]: 'authentication', [ZaloErrorCode.AUTHENTICATION_FAILED]: 'authentication', [ZaloErrorCode.USER_NOT_FOUND]: 'user_info', [ZaloErrorCode.USER_ID_INVALID]: 'user_info', [ZaloErrorCode.USER_PROFILE_PRIVATE]: 'user_info', [ZaloErrorCode.USER_BLOCKED_YOU]: 'user_info', [ZaloErrorCode.USER_DOESNT_EXIST]: 'user_info', [ZaloErrorCode.USER_NOT_ACCESSIBLE]: 'user_info', [ZaloErrorCode.FRIEND_REQUEST_FAILED]: 'friend_management', [ZaloErrorCode.FRIEND_NOT_FOUND]: 'friend_management', [ZaloErrorCode.ALREADY_FRIENDS]: 'friend_management', [ZaloErrorCode.FRIEND_REQUEST_SENT]: 'friend_management', [ZaloErrorCode.CANNOT_SEND_REQUEST]: 'friend_management', [ZaloErrorCode.FRIEND_BLOCKED]: 'friend_management', [ZaloErrorCode.CANNOT_UNFRIEND]: 'friend_management', [ZaloErrorCode.GROUP_NOT_FOUND]: 'group_management', [ZaloErrorCode.GROUP_ID_INVALID]: 'group_management', [ZaloErrorCode.NOT_GROUP_MEMBER]: 'group_management', [ZaloErrorCode.NOT_GROUP_ADMIN]: 'group_management', [ZaloErrorCode.GROUP_FULL]: 'group_management', [ZaloErrorCode.CANNOT_JOIN_GROUP]: 'group_management', [ZaloErrorCode.GROUP_CREATION_FAILED]: 'group_management', [ZaloErrorCode.GROUP_SETTINGS_UPDATE_FAILED]: 'group_management', [ZaloErrorCode.MESSAGE_NOT_FOUND]: 'messaging', [ZaloErrorCode.CANNOT_SEND_MESSAGE]: 'messaging', [ZaloErrorCode.MEDIA_TOO_LARGE]: 'messaging', [ZaloErrorCode.UNSUPPORTED_MEDIA_TYPE]: 'messaging', [ZaloErrorCode.MESSAGE_SEND_FAILED]: 'messaging', [ZaloErrorCode.MESSAGE_FORWARD_FAILED]: 'messaging', [ZaloErrorCode.REACTION_FAILED]: 'messaging', [ZaloErrorCode.INVALID_PARAMETERS]: 'validation', [ZaloErrorCode.MISSING_REQUIRED_FIELDS]: 'validation', [ZaloErrorCode.INVALID_USER_ID_FORMAT]: 'validation', [ZaloErrorCode.INVALID_GROUP_ID_FORMAT]: 'validation', [ZaloErrorCode.INVALID_MESSAGE_FORMAT]: 'validation', [ZaloErrorCode.BATCH_SIZE_EXCEEDED]: 'validation', [ZaloErrorCode.INVALID_ATTACHMENT_FORMAT]: 'validation', [ZaloErrorCode.RATE_LIMIT_EXCEEDED]: 'rate_limiting', [ZaloErrorCode.TOO_MANY_REQUESTS]: 'rate_limiting', [ZaloErrorCode.TEMPORARY_BLOCK]: 'rate_limiting', [ZaloErrorCode.REQUEST_LIMIT_REACHED]: 'rate_limiting', [ZaloErrorCode.SPAM_DETECTED]: 'rate_limiting', [ZaloErrorCode.NETWORK_ERROR]: 'network', [ZaloErrorCode.CONNECTION_TIMEOUT]: 'network', [ZaloErrorCode.API_UNAVAILABLE]: 'network', [ZaloErrorCode.SERVER_ERROR]: 'network', [ZaloErrorCode.CONNECTION_REFUSED]: 'network', [ZaloErrorCode.DNS_RESOLUTION_FAILED]: 'network', [ZaloErrorCode.PROXY_CONNECTION_FAILED]: 'network', [ZaloErrorCode.INSUFFICIENT_PERMISSIONS]: 'permission', [ZaloErrorCode.ACCESS_DENIED]: 'permission', [ZaloErrorCode.ACCOUNT_SUSPENDED]: 'permission', [ZaloErrorCode.ACCOUNT_BANNED]: 'permission', [ZaloErrorCode.DEVICE_NOT_VERIFIED]: 'permission', [ZaloErrorCode.REGION_RESTRICTED]: 'permission', [ZaloErrorCode.AGE_RESTRICTED]: 'permission', [ZaloErrorCode.OPERATION_NOT_ALLOWED]: 'business_logic', [ZaloErrorCode.FEATURE_NOT_AVAILABLE]: 'business_logic', [ZaloErrorCode.SUBSCRIPTION_REQUIRED]: 'business_logic', [ZaloErrorCode.QUOTA_EXCEEDED]: 'business_logic', [ZaloErrorCode.INVALID_OPERATION_CONTEXT]: 'business_logic', [ZaloErrorCode.DATA_PARSING_FAILED]: 'data_processing', [ZaloErrorCode.ENCRYPTION_FAILED]: 'data_processing', [ZaloErrorCode.DECRYPTION_FAILED]: 'data_processing', [ZaloErrorCode.DATA_CORRUPTION]: 'data_processing', [ZaloErrorCode.INVALID_JSON_FORMAT]: 'data_processing', [ZaloErrorCode.EXTERNAL_API_ERROR]: 'external_service', [ZaloErrorCode.WEBHOOK_DELIVERY_FAILED]: 'external_service', [ZaloErrorCode.CALLBACK_TIMEOUT]: 'external_service', [ZaloErrorCode.THIRD_PARTY_SERVICE_ERROR]: 'external_service', [ZaloErrorCode.UNKNOWN_ERROR]: 'generic', [ZaloErrorCode.INTERNAL_ERROR]: 'generic', [ZaloErrorCode.INVALID_RESPONSE]: 'generic', [ZaloErrorCode.UNEXPECTED_ERROR]: 'generic', [ZaloErrorCode.NOT_IMPLEMENTED]: 'generic', [ZaloErrorCode.MAINTENANCE_MODE]: 'generic', }; /** * Error Severity Mappings */ exports.ERROR_SEVERITY = { [ZaloErrorCode.SESSION_NOT_FOUND]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.SESSION_EXPIRED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.SESSION_INACTIVE]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.INVALID_CREDENTIALS]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.AUTHENTICATION_FAILED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.USER_NOT_FOUND]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.USER_ID_INVALID]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.USER_PROFILE_PRIVATE]: ZaloErrorSeverity.LOW, [ZaloErrorCode.USER_BLOCKED_YOU]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.USER_DOESNT_EXIST]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.USER_NOT_ACCESSIBLE]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.FRIEND_REQUEST_FAILED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.FRIEND_NOT_FOUND]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.ALREADY_FRIENDS]: ZaloErrorSeverity.LOW, [ZaloErrorCode.FRIEND_REQUEST_SENT]: ZaloErrorSeverity.LOW, [ZaloErrorCode.CANNOT_SEND_REQUEST]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.FRIEND_BLOCKED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.CANNOT_UNFRIEND]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.GROUP_NOT_FOUND]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.GROUP_ID_INVALID]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.NOT_GROUP_MEMBER]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.NOT_GROUP_ADMIN]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.GROUP_FULL]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.CANNOT_JOIN_GROUP]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.GROUP_CREATION_FAILED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.GROUP_SETTINGS_UPDATE_FAILED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.MESSAGE_NOT_FOUND]: ZaloErrorSeverity.LOW, [ZaloErrorCode.CANNOT_SEND_MESSAGE]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.MEDIA_TOO_LARGE]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.UNSUPPORTED_MEDIA_TYPE]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.MESSAGE_SEND_FAILED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.MESSAGE_FORWARD_FAILED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.REACTION_FAILED]: ZaloErrorSeverity.LOW, [ZaloErrorCode.INVALID_PARAMETERS]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.MISSING_REQUIRED_FIELDS]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.INVALID_USER_ID_FORMAT]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.INVALID_GROUP_ID_FORMAT]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.INVALID_MESSAGE_FORMAT]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.BATCH_SIZE_EXCEEDED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.INVALID_ATTACHMENT_FORMAT]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.RATE_LIMIT_EXCEEDED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.TOO_MANY_REQUESTS]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.TEMPORARY_BLOCK]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.REQUEST_LIMIT_REACHED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.SPAM_DETECTED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.NETWORK_ERROR]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.CONNECTION_TIMEOUT]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.API_UNAVAILABLE]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.SERVER_ERROR]: ZaloErrorSeverity.CRITICAL, [ZaloErrorCode.CONNECTION_REFUSED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.DNS_RESOLUTION_FAILED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.PROXY_CONNECTION_FAILED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.INSUFFICIENT_PERMISSIONS]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.ACCESS_DENIED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.ACCOUNT_SUSPENDED]: ZaloErrorSeverity.CRITICAL, [ZaloErrorCode.ACCOUNT_BANNED]: ZaloErrorSeverity.CRITICAL, [ZaloErrorCode.DEVICE_NOT_VERIFIED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.REGION_RESTRICTED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.AGE_RESTRICTED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.OPERATION_NOT_ALLOWED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.FEATURE_NOT_AVAILABLE]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.SUBSCRIPTION_REQUIRED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.QUOTA_EXCEEDED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.INVALID_OPERATION_CONTEXT]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.DATA_PARSING_FAILED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.ENCRYPTION_FAILED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.DECRYPTION_FAILED]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.DATA_CORRUPTION]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.INVALID_JSON_FORMAT]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.EXTERNAL_API_ERROR]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.WEBHOOK_DELIVERY_FAILED]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.CALLBACK_TIMEOUT]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.THIRD_PARTY_SERVICE_ERROR]: ZaloErrorSeverity.HIGH, [ZaloErrorCode.UNKNOWN_ERROR]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.INTERNAL_ERROR]: ZaloErrorSeverity.CRITICAL, [ZaloErrorCode.INVALID_RESPONSE]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.UNEXPECTED_ERROR]: ZaloErrorSeverity.MEDIUM, [ZaloErrorCode.NOT_IMPLEMENTED]: ZaloErrorSeverity.LOW, [ZaloErrorCode.MAINTENANCE_MODE]: ZaloErrorSeverity.HIGH, }; /** * Standardized Error Messages */ exports.ERROR_MESSAGES = { // Authentication & Session Errors [ZaloErrorCode.SESSION_NOT_FOUND]: 'Session not found or inactive. Please login again.', [ZaloErrorCode.SESSION_EXPIRED]: 'Session has expired. Please login again.', [ZaloErrorCode.SESSION_INACTIVE]: 'Session is inactive. Please login again.', [ZaloErrorCode.INVALID_CREDENTIALS]: 'Invalid credentials provided. Please check your login information.', [ZaloErrorCode.AUTHENTICATION_FAILED]: 'Authentication failed. Please try again.', [ZaloErrorCode.SESSION_CREATION_FAILED]: 'Failed to create session. Please try again.', [ZaloErrorCode.SESSION_VALIDATION_FAILED]: 'Session validation failed. Please login again.', // User Information Errors [ZaloErrorCode.USER_NOT_FOUND]: 'User not found or does not exist.', [ZaloErrorCode.USER_ID_INVALID]: 'Invalid user ID format provided.', [ZaloErrorCode.USER_PROFILE_PRIVATE]: 'User profile is private or not accessible.', [ZaloErrorCode.USER_BLOCKED_YOU]: 'User has blocked you or you have blocked this user.', [ZaloErrorCode.USER_DOESNT_EXIST]: 'User does not exist.', [ZaloErrorCode.USER_NOT_ACCESSIBLE]: 'User information is not accessible.', // Friend Management Errors [ZaloErrorCode.FRIEND_REQUEST_FAILED]: 'Failed to send friend request.', [ZaloErrorCode.FRIEND_NOT_FOUND]: 'Friend not found.', [ZaloErrorCode.ALREADY_FRIENDS]: 'Users are already friends.', [ZaloErrorCode.FRIEND_REQUEST_SENT]: 'Friend request has already been sent.', [ZaloErrorCode.CANNOT_SEND_REQUEST]: 'Cannot send friend request at this time.', [ZaloErrorCode.FRIEND_BLOCKED]: 'Friend request blocked due to privacy settings.', [ZaloErrorCode.CANNOT_UNFRIEND]: 'Cannot unfriend this user.', // Group Management Errors [ZaloErrorCode.GROUP_NOT_FOUND]: 'Group not found.', [ZaloErrorCode.GROUP_ID_INVALID]: 'Invalid group ID format.', [ZaloErrorCode.NOT_GROUP_MEMBER]: 'You are not a member of this group.', [ZaloErrorCode.NOT_GROUP_ADMIN]: 'You are not an admin of this group.', [ZaloErrorCode.GROUP_FULL]: 'Group is full and cannot accept more members.', [ZaloErrorCode.CANNOT_JOIN_GROUP]: 'Cannot join this group.', [ZaloErrorCode.GROUP_CREATION_FAILED]: 'Failed to create group.', [ZaloErrorCode.GROUP_SETTINGS_UPDATE_FAILED]: 'Failed to update group settings.', // Message & Media Errors [ZaloErrorCode.MESSAGE_NOT_FOUND]: 'Message not found.', [ZaloErrorCode.CANNOT_SEND_MESSAGE]: 'Cannot send message at this time.', [ZaloErrorCode.MEDIA_TOO_LARGE]: 'Media file is too large.', [ZaloErrorCode.UNSUPPORTED_MEDIA_TYPE]: 'Unsupported media type.', [ZaloErrorCode.MESSAGE_SEND_FAILED]: 'Failed to send message.', [ZaloErrorCode.MESSAGE_FORWARD_FAILED]: 'Failed to forward message.', [ZaloErrorCode.REACTION_FAILED]: 'Failed to add reaction.', // Request Validation Errors [ZaloErrorCode.INVALID_PARAMETERS]: 'Invalid request parameters.', [ZaloErrorCode.MISSING_REQUIRED_FIELDS]: 'Missing required fields in request.', [ZaloErrorCode.INVALID_USER_ID_FORMAT]: 'Invalid user ID format.', [ZaloErrorCode.INVALID_GROUP_ID_FORMAT]: 'Invalid group ID format.', [ZaloErrorCode.INVALID_MESSAGE_FORMAT]: 'Invalid message format.', [ZaloErrorCode.BATCH_SIZE_EXCEEDED]: 'Batch size limit exceeded.', [ZaloErrorCode.INVALID_ATTACHMENT_FORMAT]: 'Invalid attachment format.', // Rate Limiting Errors [ZaloErrorCode.RATE_LIMIT_EXCEEDED]: 'Rate limit exceeded. Please try again later.', [ZaloErrorCode.TOO_MANY_REQUESTS]: 'Too many requests. Please slow down.', [ZaloErrorCode.TEMPORARY_BLOCK]: 'Account temporarily blocked. Please try again later.', [ZaloErrorCode.REQUEST_LIMIT_REACHED]: 'Request limit reached. Please wait before trying again.', [ZaloErrorCode.SPAM_DETECTED]: 'Spam activity detected. Please verify your actions.', // Network & Connection Errors [ZaloErrorCode.NETWORK_ERROR]: 'Network error occurred. Please check your connection.', [ZaloErrorCode.CONNECTION_TIMEOUT]: 'Connection timeout. Please try again.', [ZaloErrorCode.API_UNAVAILABLE]: 'Zalo API is currently unavailable. Please try again later.', [ZaloErrorCode.SERVER_ERROR]: 'Zalo server error occurred. Please try again later.', [ZaloErrorCode.CONNECTION_REFUSED]: 'Connection refused by server.', [ZaloErrorCode.DNS_RESOLUTION_FAILED]: 'DNS resolution failed.', [ZaloErrorCode.PROXY_CONNECTION_FAILED]: 'Proxy connection failed.', // Permission & Access Errors [ZaloErrorCode.INSUFFICIENT_PERMISSIONS]: 'Insufficient permissions to perform this action.', [ZaloErrorCode.ACCESS_DENIED]: 'Access denied. You do not have permission to perform this action.', [ZaloErrorCode.ACCOUNT_SUSPENDED]: 'Account has been suspended. Please contact support.', [ZaloErrorCode.ACCOUNT_BANNED]: 'Account has been banned. Please contact support.', [ZaloErrorCode.DEVICE_NOT_VERIFIED]: 'Device not verified. Please verify your device.', [ZaloErrorCode.REGION_RESTRICTED]: 'This feature is not available in your region.', [ZaloErrorCode.AGE_RESTRICTED]: 'Age restricted content. Please verify your age.', // Business Logic Errors [ZaloErrorCode.OPERATION_NOT_ALLOWED]: 'Operation not allowed in current context.', [ZaloErrorCode.FEATURE_NOT_AVAILABLE]: 'Feature is not available.', [ZaloErrorCode.SUBSCRIPTION_REQUIRED]: 'Premium subscription required for this feature.', [ZaloErrorCode.QUOTA_EXCEEDED]: 'Daily/monthly quota exceeded. Please try again later.', [ZaloErrorCode.INVALID_OPERATION_CONTEXT]: 'Invalid operation context.', // Data Processing Errors [ZaloErrorCode.DATA_PARSING_FAILED]: 'Failed to parse data.', [ZaloErrorCode.ENCRYPTION_FAILED]: 'Failed to encrypt data.', [ZaloErrorCode.DECRYPTION_FAILED]: 'Failed to decrypt data.', [ZaloErrorCode.DATA_CORRUPTION]: 'Data corruption detected.', [ZaloErrorCode.INVALID_JSON_FORMAT]: 'Invalid JSON format.', // External Service Errors [ZaloErrorCode.EXTERNAL_API_ERROR]: 'External API error occurred.', [ZaloErrorCode.WEBHOOK_DELIVERY_FAILED]: 'Webhook delivery failed.', [ZaloErrorCode.CALLBACK_TIMEOUT]: 'Callback timeout occurred.', [ZaloErrorCode.THIRD_PARTY_SERVICE_ERROR]: 'Third party service error.', // Generic Errors [ZaloErrorCode.UNKNOWN_ERROR]: 'An unknown error occurred.', [ZaloErrorCode.INTERNAL_ERROR]: 'Internal server error occurred.', [ZaloErrorCode.INVALID_RESPONSE]: 'Invalid response received.', [ZaloErrorCode.UNEXPECTED_ERROR]: 'An unexpected error occurred.', [ZaloErrorCode.NOT_IMPLEMENTED]: 'Feature not implemented yet.', [ZaloErrorCode.MAINTENANCE_MODE]: 'Service is currently under maintenance.', }; /** * Error context builder helper */ class ZaloErrorContext { constructor() { this.details = {}; } /** * Set error code */ code(code) { this.details.code = code; this.details.category = exports.ERROR_CATEGORIES[code]; this.details.severity = exports.ERROR_SEVERITY[code]; this.details.message = exports.ERROR_MESSAGES[code]; return this; } /** * Set custom message */ message(message) { this.details.message = message; return this; } /** * Add context */ context(context) { this.details.context = { ...this.details.context, ...context }; return this; } /** * Set session ID */ sessionId(sessionId) { this.details.sessionId = sessionId; return this; } /** * Set user ID */ userId(userId) { this.details.userId = userId; return this; } /** * Set group ID */ groupId(groupId) { this.details.groupId = groupId; return this; } /** * Set request ID */ requestId(requestId) { this.details.requestId = requestId; return this; } /** * Set original error */ originalError(error) { this.details.originalError = error; return this; } /** * Build the error details */ build() { return { code: this.details.code || ZaloErrorCode.UNKNOWN_ERROR, message: this.details.message || exports.ERROR_MESSAGES[ZaloErrorCode.UNKNOWN_ERROR], category: this.details.category || 'generic', severity: this.details.severity || ZaloErrorSeverity.MEDIUM, timestamp: Date.now(), context: this.details.context, originalError: this.details.originalError, requestId: this.details.requestId, sessionId: this.details.sessionId, userId: this.details.userId, groupId: this.details.groupId, }; } } exports.ZaloErrorContext = ZaloErrorContext; /** * Utility functions for error handling */ class ZaloErrorUtils { /** * Create a standardized error response */ static createErrorResponse(code, customMessage, context) { const errorContext = new ZaloErrorContext() .code(code) .message(customMessage || exports.ERROR_MESSAGES[code]) .context(context || {}) .build(); return { success: false, error: errorContext, metadata: context, }; } /** * Check if an error is recoverable */ static isRecoverable(errorCode) { const unrecoverableCodes = [ ZaloErrorCode.ACCOUNT_BANNED, ZaloErrorCode.AGE_RESTRICTED, ZaloErrorCode.REGION_RESTRICTED, ZaloErrorCode.DEVICE_NOT_VERIFIED, ]; return !unrecoverableCodes.includes(errorCode); } /** * Check if an error should trigger a retry */ static shouldRetry(errorCode) { const retryableCodes = [ ZaloErrorCode.NETWORK_ERROR, ZaloErrorCode.CONNECTION_TIMEOUT, ZaloErrorCode.API_UNAVAILABLE, ZaloErrorCode.SERVER_ERROR, ZaloErrorCode.RATE_LIMIT_EXCEEDED, ZaloErrorCode.TEMPORARY_BLOCK, ]; return retryableCodes.includes(errorCode); } /** * Get retry delay in milliseconds for a specific error code */ static getRetryDelay(errorCode) { const retryDelays = { [ZaloErrorCode.RATE_LIMIT_EXCEEDED]: 60000, // 1 minute [ZaloErrorCode.TEMPORARY_BLOCK]: 300000, // 5 minutes [ZaloErrorCode.TOO_MANY_REQUESTS]: 30000, // 30 seconds [ZaloErrorCode.NETWORK_ERROR]: 5000, // 5 seconds [ZaloErrorCode.CONNECTION_TIMEOUT]: 10000, // 10 seconds [ZaloErrorCode.API_UNAVAILABLE]: 30000, // 30 seconds [ZaloErrorCode.SERVER_ERROR]: 15000, // 15 seconds }; return retryDelays[errorCode] || 5000; // Default 5 seconds } /** * Format error for logging */ static formatForLogging(error) { return `[${error.category.toUpperCase()}] ${error.code}: ${error.message}${error.sessionId ? ` (Session: ${error.sessionId})` : ''}${error.userId ? ` (User: ${error.userId})` : ''}${error.groupId ? ` (Group: ${error.groupId})` : ''}${error.requestId ? ` (Request: ${error.requestId})` : ''}`; } /** * Check if error is session-related */ static isSessionError(errorCode) { const sessionErrorCodes = [ ZaloErrorCode.SESSION_NOT_FOUND, ZaloErrorCode.SESSION_EXPIRED, ZaloErrorCode.SESSION_INACTIVE, ZaloErrorCode.INVALID_CREDENTIALS, ZaloErrorCode.AUTHENTICATION_FAILED, ]; return sessionErrorCodes.includes(errorCode); } /** * Check if error is user-related */ static isUserError(errorCode) { const userErrorCodes = [ ZaloErrorCode.USER_NOT_FOUND, ZaloErrorCode.USER_ID_INVALID, ZaloErrorCode.USER_PROFILE_PRIVATE, ZaloErrorCode.USER_BLOCKED_YOU, ZaloErrorCode.USER_DOESNT_EXIST, ZaloErrorCode.USER_NOT_ACCESSIBLE, ]; return userErrorCodes.includes(errorCode); } /** * Check if error is group-related */ static isGroupError(errorCode) { const groupErrorCodes = [ ZaloErrorCode.GROUP_NOT_FOUND, ZaloErrorCode.GROUP_ID_INVALID, ZaloErrorCode.NOT_GROUP_MEMBER, ZaloErrorCode.NOT_GROUP_ADMIN, ZaloErrorCode.GROUP_FULL, ZaloErrorCode.CANNOT_JOIN_GROUP, ZaloErrorCode.GROUP_CREATION_FAILED, ZaloErrorCode.GROUP_SETTINGS_UPDATE_FAILED, ]; return groupErrorCodes.includes(errorCode); } } exports.ZaloErrorUtils = ZaloErrorUtils; //# sourceMappingURL=error.types.js.map