diff --git a/NexmoClient/Exceptions/NexmoClientException.php b/NexmoClient/Exceptions/NexmoClientException.php new file mode 100644 index 0000000..a628d21 --- /dev/null +++ b/NexmoClient/Exceptions/NexmoClientException.php @@ -0,0 +1,11 @@ + + */ +class NexmoClientException extends \Exception { + +} \ No newline at end of file diff --git a/NexmoClient/Exceptions/QuotaExcededException.php b/NexmoClient/Exceptions/QuotaExcededException.php index 4445bfd..a251c30 100644 --- a/NexmoClient/Exceptions/QuotaExcededException.php +++ b/NexmoClient/Exceptions/QuotaExcededException.php @@ -6,6 +6,6 @@ namespace Jhg\NexmoBundle\NexmoClient\Exceptions; * @package Jhg\NexmoBundle\NexmoClient\Exceptions * @author Javi Hernández */ -class QuotaExcededException extends \Exception { +class QuotaExcededException extends NexmoClientException { } \ No newline at end of file diff --git a/NexmoClient/Exceptions/UnroutableSmsMessageException.php b/NexmoClient/Exceptions/UnroutableSmsMessageException.php index facc46f..85f1b4d 100644 --- a/NexmoClient/Exceptions/UnroutableSmsMessageException.php +++ b/NexmoClient/Exceptions/UnroutableSmsMessageException.php @@ -6,6 +6,6 @@ namespace Jhg\NexmoBundle\NexmoClient\Exceptions; * @package Jhg\NexmoBundle\NexmoClient\Exceptions * @author Javi Hernández */ -class UnroutableSmsMessageException extends \Exception { +class UnroutableSmsMessageException extends NexmoClientException { } \ No newline at end of file diff --git a/NexmoClient/NexmoClient.php b/NexmoClient/NexmoClient.php index ed96bba..3ba28ac 100644 --- a/NexmoClient/NexmoClient.php +++ b/NexmoClient/NexmoClient.php @@ -1,6 +1,7 @@ disable_delivery) { $this->logger->debug("Nexmo sendTextMessage delivery disabled by config"); - return null; + return array( + "status" => "0", + "message-id" => "delivery-disabled", + "to" => $toNumber, + "client-ref" => 0, + "remaining-balance" => 0, + "message-price" => 0, + "network" => 0, + ); } $response = $this->jsonRequest('/sms/json',$params); - if((int)$response['messages'][0]['status']!=0) { - switch((int)$response['messages'][0]['status']) { + if(0 !== $code = (int)$response['messages'][0]['status']) { + $error = $response['messages'][0]['error-text']; + switch( $code) { case 6: - throw new UnroutableSmsMessageException(); + throw new UnroutableSmsMessageException($error, $code); case 9: - throw new QuotaExcededException(); + throw new QuotaExcededException($error, $code); default: - throw new \Exception($response['messages'][0]['error-text'],(int)$response['messages'][0]['status']); + throw new NexmoClientException($error, $code); } }