public static function ShareaholicUtilities::has_bad_response in Share Buttons, Related Posts, Content Analytics - Shareaholic 7.3
Same name and namespace in other branches
- 8 utilities.php \ShareaholicUtilities::has_bad_response()
Checks bad response and logs errors if any
Return value
boolean
2 calls to ShareaholicUtilities::has_bad_response()
- ShareaholicUtilities::api_key_verified in ./
utilities.php - Checks whether the api key has been verified using the rails endpoint. Once the key has been verified, we store that away so that we don't have to check again.
- ShareaholicUtilities::get_or_create_api_key in ./
utilities.php - Returns the api key or creates a new one.
File
- ./
utilities.php, line 422
Class
Code
public static function has_bad_response($response, $type, $json_parse = FALSE) {
if (!$response) {
ShareaholicUtilities::log_event($type, array(
'reason' => 'there was no response',
));
return true;
}
$response = (array) $response;
if (isset($response['error'])) {
$error_message = print_r($response['error'], true);
ShareaholicUtilities::log_event($type, array(
'reason' => 'there was an error: ' . $error_message,
));
return true;
}
if (!preg_match('/20*/', $response['code'])) {
ShareaholicUtilities::log_event($type, array(
'reason' => 'the server responded with code ' . $response['code'],
));
return true;
}
if ($json_parse && json_decode($response['data']) === NULL) {
ShareaholicUtilities::log_event($type, array(
'reason' => 'could not parse JSON. The response was: ' . $response['data'],
));
return true;
}
return false;
}