diff --git a/src/Snowcap/Emarsys/Client.php b/src/Snowcap/Emarsys/Client.php index 875be62..95ecb96 100644 --- a/src/Snowcap/Emarsys/Client.php +++ b/src/Snowcap/Emarsys/Client.php @@ -893,7 +893,7 @@ public function addBlacklistEntries(array $emails = array(), array $domains = ar * @throws ClientException * @throws ServerException */ - protected function send($method = 'GET', $uri, array $body = array()) + protected function send(string $method, $uri, array $body = array()) { $headers = array('Content-Type: application/json', 'X-WSSE: ' . $this->getAuthenticationSignature()); $uri = $this->baseUrl . $uri; @@ -911,7 +911,9 @@ protected function send($method = 'GET', $uri, array $body = array()) case JSON_ERROR_DEPTH: throw new ClientException('JSON response could not be decoded, maximum depth reached.'); default: - throw new ServerException("JSON response could not be decoded:\n" . json_last_error_msg()); + $exception = new ServerException("JSON response could not be decoded:\n" . json_last_error_msg()); + $exception->setResponseMessage($responseJson); + throw $exception; } } diff --git a/src/Snowcap/Emarsys/Exception/ServerException.php b/src/Snowcap/Emarsys/Exception/ServerException.php index f164cf5..205fb62 100644 --- a/src/Snowcap/Emarsys/Exception/ServerException.php +++ b/src/Snowcap/Emarsys/Exception/ServerException.php @@ -5,5 +5,27 @@ class ServerException extends \Exception { + protected $responseMessage = null; -} \ No newline at end of file + /** + * Set the response message from the server + * + * @param string $message + * @author David Fox + */ + public function setResponseMessage($message) + { + $this->responseMessage = $message; + } + + /** + * Return the response message set on this exception + * + * @return string + * @author David Fox + */ + public function getResponseMessage() + { + return $this->responseMessage; + } +}