From 5e9b7d67b617af4bd014c3379716e26a2887b8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Pleple=CC=81?= Date: Wed, 13 Jul 2011 16:40:13 -0700 Subject: [PATCH] added empty response error handling --- main/mashape/exceptions/ExceptionConstants.php | 1 + main/mashape/http/HttpClient.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/main/mashape/exceptions/ExceptionConstants.php b/main/mashape/exceptions/ExceptionConstants.php index 479153c..84a6230 100644 --- a/main/mashape/exceptions/ExceptionConstants.php +++ b/main/mashape/exceptions/ExceptionConstants.php @@ -29,5 +29,6 @@ define("EXCEPTION_NOTSUPPORTED_HTTPMETHOD", "HTTP method not supported. Only DEL define("EXCEPTION_SYSTEM_ERROR_CODE", 2000); define("EXCEPTION_JSONDECODE_REQUEST", "Can't deserialize the response JSON from the component. The method returned an invalid JSON value: %s"); +define("EXCEPTION_EMPTY_RESPONSE", "Can't deserialize the response JSON from the component. The method returned an empty value."); ?> diff --git a/main/mashape/http/HttpClient.php b/main/mashape/http/HttpClient.php index d5b8352..4ce50f1 100644 --- a/main/mashape/http/HttpClient.php +++ b/main/mashape/http/HttpClient.php @@ -17,6 +17,9 @@ class HttpClient { UrlUtils::prepareRequest($url, $parameters, ($httpMethod != HttpMethod::GET) ? true : false); $response = self::execRequest($httpMethod, $url, $parameters); + if (empty($response)) { + throw new MashapeClientException(EXCEPTION_EMPTY_RESPONSE, EXCEPTION_SYSTEM_ERROR_CODE); + } $jsonResponse = json_decode($response); if (empty($jsonResponse)) {