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.
  • Invalid list queries for messages or credit orders: an unknown sort, a limit outside 1 to 100, a date without an offset or that does not exist, a dateFrom that is not before dateTo, an empty cursor, or an unknown key.
  • 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.
  • Treat 422 as a request the API refused: invalid parameters, a cursor issued for another sort, or a schedule state change that is not allowed, such as disabling a schedule that is not active.
  • Inspect getResultDescription() for API validation details.
  • Retry only failures that your application knows are transient; do not blindly retry local validation or authentication failures.