added empty response error handling

This commit is contained in:
Quentin Pleplé
2011-07-13 16:40:13 -07:00
parent 1dd7264e9b
commit 5e9b7d67b6
2 changed files with 4 additions and 0 deletions

View File

@@ -29,5 +29,6 @@ define("EXCEPTION_NOTSUPPORTED_HTTPMETHOD", "HTTP method not supported. Only DEL
define("EXCEPTION_SYSTEM_ERROR_CODE", 2000); 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_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.");
?> ?>

View File

@@ -17,6 +17,9 @@ class HttpClient {
UrlUtils::prepareRequest($url, $parameters, ($httpMethod != HttpMethod::GET) ? true : false); UrlUtils::prepareRequest($url, $parameters, ($httpMethod != HttpMethod::GET) ? true : false);
$response = self::execRequest($httpMethod, $url, $parameters); $response = self::execRequest($httpMethod, $url, $parameters);
if (empty($response)) {
throw new MashapeClientException(EXCEPTION_EMPTY_RESPONSE, EXCEPTION_SYSTEM_ERROR_CODE);
}
$jsonResponse = json_decode($response); $jsonResponse = json_decode($response);
if (empty($jsonResponse)) { if (empty($jsonResponse)) {