diff --git a/phpFlickr.php b/phpFlickr.php index d231e15..8f273bc 100644 --- a/phpFlickr.php +++ b/phpFlickr.php @@ -209,7 +209,7 @@ function post ($data, $type = null) { } if ( !preg_match("|https://(.*?)(/.*)|", $url, $matches) ) { - die('There was some problem figuring out your endpoint'); + throw new Exception('There was some problem figuring out your endpoint'); } if ( function_exists('curl_init') ) { @@ -229,7 +229,7 @@ function post ($data, $type = null) { $fp = @pfsockopen($matches[1], 80); if (!$fp) { - die('Could not connect to the web service'); + throw new Exception('Could not connect to the web service'); } fputs ($fp,'POST ' . $matches[2] . " HTTP/1.1\n"); fputs ($fp,'Host: ' . $matches[1] . "\n"); @@ -245,7 +245,7 @@ function post ($data, $type = null) { $chunked = false; $http_status = trim(substr($response, 0, strpos($response, "\n"))); if ( $http_status != 'HTTP/1.1 200 OK' ) { - die('The web service endpoint returned a "' . $http_status . '" response'); + throw new Exception('The web service endpoint returned a "' . $http_status . '" response'); } if ( strpos($response, 'Transfer-Encoding: chunked') !== false ) { $temp = trim(strstr($response, "\r\n\r\n")); @@ -303,8 +303,9 @@ function request ($command, $args = array(), $nocache = false) //$this->parsed_response = unserialize($this->response); $this->parsed_response = $this->clean_text_nodes(unserialize($this->response)); if ($this->parsed_response['stat'] == 'fail') { - if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); - else { + if ($this->die_on_error){ + throw new Exception("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); + }else { $this->error_code = $this->parsed_response['code']; $this->error_msg = $this->parsed_response['message']; $this->parsed_response = false; @@ -424,7 +425,7 @@ function sync_upload ($photo, $title = null, $description = null, $tags = null, foreach ($rsp as $line) { if (preg_match('|die_on_error) - die("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); + throw new Excetion("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); else { $this->error_code = $match[1]; $this->error_msg = $match[2]; @@ -439,7 +440,7 @@ function sync_upload ($photo, $title = null, $description = null, $tags = null, } } else { - die("Sorry, your server must support CURL in order to upload files"); + throw new Exception("Sorry, your server must support CURL in order to upload files"); } } @@ -486,7 +487,7 @@ function async_upload ($photo, $title = null, $description = null, $tags = null, foreach ($rsp as $line) { if (preg_match('/die_on_error) - die("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); + throw new Exception("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); else { $this->error_code = $match[1]; $this->error_msg = $match[2]; @@ -500,7 +501,7 @@ function async_upload ($photo, $title = null, $description = null, $tags = null, } } } else { - die("Sorry, your server must support CURL in order to upload files"); + throw new Exception("Sorry, your server must support CURL in order to upload files"); } } @@ -552,7 +553,7 @@ function replace ($photo, $photo_id, $async = null) { foreach ($rsp as $line) { if (preg_match('|die_on_error) - die("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); + throw new Exception("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); else { $this->error_code = $match[1]; $this->error_msg = $match[2]; @@ -566,7 +567,7 @@ function replace ($photo, $photo_id, $async = null) { } } } else { - die("Sorry, your server must support CURL in order to upload files"); + throw new Exception("Sorry, your server must support CURL in order to upload files"); } }