Skip to content

Commit

Permalink
Merge pull request #7 from ConvertKit/dont-crash-on-timeout
Browse files Browse the repository at this point in the history
Avoid crashing on timeout
  • Loading branch information
marcboquet committed Feb 17, 2016
2 parents 5224675 + 6fe95ac commit caaed6c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/convertkit-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function get_resources($resource) {
if(!array_key_exists($resource, $this->resources)) {
$api_response = $this->_get_api_response($resource);

if (is_wp_error($api_response) || isset($api_response['error']) || isset($api_response['error_message'])) {
if (is_null($api_response) || is_wp_error($api_response) || isset($api_response['error']) || isset($api_response['error_message'])) {
$this->resources[$resource] = array();
} else {
$this->resources[$resource] = $api_response;
Expand Down Expand Up @@ -82,7 +82,7 @@ public function get_resource($url) {
if(!empty($url) && isset($this->markup[$url])) {
$resource = $this->markup[$url];
} else if(!empty($url)) {
$response = wp_remote_get($url);
$response = wp_remote_get($url, array( 'timeout' => 2 ));

if(!is_wp_error($response)) {
if(!function_exists('str_get_html')) {
Expand Down Expand Up @@ -128,7 +128,7 @@ private function _get_api_response($path = '') {
$args = array('k' => $this->api_key, 'v' => $this->api_version);
$url = add_query_arg($args, path_join($this->api_url_base, $path));

$response = wp_remote_get($url);
$response = wp_remote_get($url, array( 'timeout' => 2 ));

if(is_wp_error($response)) {
$data = $response;
Expand Down

0 comments on commit caaed6c

Please sign in to comment.