Error Handling

The Wazera API uses standard HTTP status codes and provides detailed error responses.

Error Response Format

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "The 'to' field is required.",
    "details": {
      "to": ["The to field is required."]
    }
  }
}

Error Codes

Code HTTP Status Description
VALIDATION_ERROR 400 Invalid request parameters
INVALID_PHONE 400 Invalid phone number format
TEMPLATE_NOT_FOUND 400 Template does not exist
AUTHENTICATION_ERROR 401 Invalid or missing API key
KEY_REVOKED 401 API key has been revoked
INSUFFICIENT_PERMISSIONS 403 Key lacks required scope
PLAN_LIMIT_EXCEEDED 403 Plan limit reached
RESOURCE_NOT_FOUND 404 Resource does not exist
RATE_LIMIT_EXCEEDED 429 Too many requests
WHATSAPP_ERROR 502 WhatsApp API returned an error
INTERNAL_ERROR 500 Unexpected server error

Handling Errors

cURL

curl -s -w "\n%{http_code}" \
  -X POST https://app.wazera.com/api/v1/messages/send \
  -H "X-API-Key: wz_live_invalid_key" \
  -H "Content-Type: application/json" \
  -d '{"to": "invalid", "message": "test"}'

PHP

$response = Wazera::sendMessage([...]);

if (!$response->successful()) {
    $error = $response->error();
    echo "Error: {$error['code']} - {$error['message']}";
}

Laravel Package Exceptions

use Wazera\Laravel\Exceptions\WazeraException;
use Wazera\Laravel\Exceptions\ValidationException;
use Wazera\Laravel\Exceptions\RateLimitException;
use Wazera\Laravel\Exceptions\AuthenticationException;
use Wazera\Laravel\Exceptions\PlanLimitException;

try {
    Wazera::sendMessage([...]);
} catch (ValidationException $e) {
    // $e->errors() returns validation errors array
} catch (RateLimitException $e) {
    // $e->retryAfter() returns seconds to wait
} catch (AuthenticationException $e) {
    // Invalid or revoked API key
} catch (PlanLimitException $e) {
    // Plan limit exceeded — upgrade needed
} catch (WazeraException $e) {
    // Catch-all for any Wazera error
}

Rate Limiting

When rate limited, the response includes:

HTTP/1.1 429 Too Many Requests
Retry-After: 30
X-RateLimit-Limit: 300
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1679529600

Best practice: implement exponential backoff in your integration.