Skip to main content

Overview

The WhatsApp Client SDK provides comprehensive error handling with detailed context, specific error codes, and actionable suggestions. This guide explains how to use the enhanced error system for better debugging and user experience.

🔍 Detailed Error Context

Operation details and timestamps, request/response information, phone numbers and message IDs, debugging metadata

📊 Categorized Error Codes

Configuration errors (1000-1099), API errors (2000-2099), webhook errors (3000-3099), media errors (4000-4099), and more

💡 Actionable Suggestions

Specific steps to resolve issues, context-aware recommendations, best practice guidance

🛡️ Enhanced Error Classes

Specialized error classes for different types of failures with rich debugging information

Enhanced Error Classes

EnhancedWhatsAppError (Base Class)

The base class for all enhanced errors provides detailed context and suggestions:

ApiRequestError (API Failures)

Specialized for WhatsApp API request failures:

WebhookProcessingError (Webhook Issues)

For webhook processing failures:

BufferError (Message Buffering Issues)

For message buffer overflow and processing issues:

Error Code Reference

Configuration Errors (1000-1099)

  • 1001 - MISSING_ACCESS_TOKEN
  • 1002 - MISSING_PHONE_NUMBER_ID
  • 1003 - MISSING_WEBHOOK_TOKEN
  • 1004 - INVALID_CONFIGURATION

API Errors (2000-2099)

  • 2001 - API_REQUEST_FAILED
  • 2002 - INVALID_PHONE_NUMBER
  • 2003 - MESSAGE_TOO_LONG
  • 2004 - UNSUPPORTED_MESSAGE_TYPE
  • 2005 - TEMPLATE_NOT_FOUND
  • 2006 - INVALID_MEDIA_ID

Webhook Errors (3000-3099)

  • 3001 - WEBHOOK_VERIFICATION_FAILED
  • 3002 - WEBHOOK_PARSING_FAILED
  • 3003 - WEBHOOK_HANDLER_ERROR
  • 3004 - INVALID_WEBHOOK_PAYLOAD

Media Errors (4000-4099)

  • 4001 - MEDIA_UPLOAD_FAILED
  • 4002 - MEDIA_DOWNLOAD_FAILED
  • 4003 - MEDIA_TOO_LARGE
  • 4004 - UNSUPPORTED_MEDIA_TYPE

Rate Limit Errors (5000-5099)

  • 5001 - RATE_LIMIT_EXCEEDED
  • 5002 - QUOTA_EXCEEDED

Business Verification Errors (6000-6099)

  • 6001 - BUSINESS_NOT_VERIFIED
  • 6002 - PHONE_NUMBER_NOT_VERIFIED

Buffer/Processing Errors (7000-7099)

  • 7001 - BUFFER_OVERFLOW
  • 7002 - MESSAGE_PROCESSING_FAILED
  • 7003 - HANDLER_EXECUTION_FAILED

Usage Examples

Basic Error Handling

Advanced Webhook Error Handling

Error Monitoring and Logging

Structured Error Logging

Best Practices

1. Always Check Error Types

2. Use Error Codes for Logic

3. Implement Error Recovery

Migration Guide

Before (Old Error Handling)

After (Enhanced Error Handling)

Troubleshooting Common Issues

Buffer Overflow (Error Code: 7001)

Rate Limiting (Error Code: 5001)

Invalid Access Token (Error Code: 1001)

Enhanced error handling is available in SDK version 1.4.1 and later. All error classes are backward compatible with existing error handling patterns.For more error handling patterns and best practices, check out our Best Practices Guide.