Add UnroutableSmsMessageException

This commit is contained in:
Javier Hernández Gil 2014-04-08 01:27:44 +02:00
parent 7de3c7aea9
commit 661df5ac9e
3 changed files with 21 additions and 2 deletions

View File

@ -36,7 +36,7 @@ class SmsManager
* @param string $message * @param string $message
* @param null|string $fromName * @param null|string $fromName
* @param int $status_report_req * @param int $status_report_req
* @return mixed * @return SmsSendResponse
*/ */
public function sendText($number,$message,$fromName=null,$status_report_req=0) { public function sendText($number,$message,$fromName=null,$status_report_req=0) {
$fromName = $fromName!==null ? $fromName : $this->defaultFromName; $fromName = $fromName!==null ? $fromName : $this->defaultFromName;

View File

@ -0,0 +1,11 @@
<?php
namespace Jhg\NexmoBundle\NexmoClient\Exceptions;
/**
* Class UnroutableSmsMessageException
* @package Jhg\NexmoBundle\NexmoClient\Exceptions
* @author Javi Hernández
*/
class UnroutableSmsMessageException extends \Exception {
}

View File

@ -1,6 +1,8 @@
<?php <?php
namespace Jhg\NexmoBundle\NexmoClient; namespace Jhg\NexmoBundle\NexmoClient;
use Jhg\NexmoBundle\NexmoClient\Exceptions\UnroutableSmsMessageException;
class NexmoClient { class NexmoClient {
/** /**
@ -99,8 +101,14 @@ class NexmoClient {
$response = $this->jsonRequest('/sms/json',$params); $response = $this->jsonRequest('/sms/json',$params);
if((int)$response['messages'][0]['status']!=0) { if((int)$response['messages'][0]['status']!=0) {
switch((int)$response['messages'][0]['status']) {
case 6:
throw new UnroutableSmsMessageException();
default:
throw new \Exception($response['messages'][0]['error-text']); throw new \Exception($response['messages'][0]['error-text']);
} }
}
return $response['messages'][0]; return $response['messages'][0];
} }