Merge pull request #1 from qpleple/response-error
Improve bad server response error handling
This commit is contained in:
@@ -28,6 +28,7 @@ define("EXCEPTION_NOTSUPPORTED_HTTPMETHOD_CODE", 1003);
|
||||
define("EXCEPTION_NOTSUPPORTED_HTTPMETHOD", "HTTP method not supported. Only DELETE, GET, POST, PUT are supported");
|
||||
|
||||
define("EXCEPTION_SYSTEM_ERROR_CODE", 2000);
|
||||
define("EXCEPTION_JSONDECODE_REQUEST", "Can't deserialize the response JSON from the component. The json_decode function is missing on your server or 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.");
|
||||
|
||||
?>
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user