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();}Common local validation errors
Section titled “Common local validation errors”- 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.
Operational guidance
Section titled “Operational guidance”- Log correlation IDs and status codes, but never log API keys or signing secrets.
- Treat
401as an invalid or inactive API key. - Treat
404as 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.
