Skip to content

Error handling

The SDK throws Rayo\SmsSdk\Exceptions\RayoException for local validation failures, transport failures, non-successful API responses, and malformed JSON responses.

use Rayo\SmsSdk\Exceptions\RayoException;
try {
$response = $client->sendSms([
'fromLabel' => 'MYBRAND',
'toMobileNumber' => '306912345678',
'smsBody' => 'Hello',
]);
} catch (RayoException $exception) {
$statusCode = $exception->getStatusCode();
$message = $exception->getMessage();
$apiError = $exception->getErrorMessage();
$resultCode = $exception->getResultCode();
$resultDescription = $exception->getResultDescription();
$payload = $exception->getErrorPayload();
$rawBody = $exception->getRawResponseBody();
}
  • Empty API key or base URL.
  • Unsupported base URL scheme.
  • Missing sender label or message body.
  • Message body longer than 1,000 characters.
  • No phone number or group destination.
  • Non-boolean request flags.
  • Missing or conflicting status identifiers.
  • Empty schedule ID or webhook signing secret.
  • Log correlation IDs and status codes, but never log API keys or signing secrets.
  • Treat 401 as an invalid or inactive API key.
  • Treat 404 as a missing resource and confirm the identifier.
  • Inspect getResultDescription() for API validation details.
  • Retry only failures that your application knows are transient; do not blindly retry local validation or authentication failures.