Skip to content

changed die to throw exceptions instead #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions phpFlickr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') ) {
Expand All @@ -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");
Expand All @@ -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"));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -424,7 +425,7 @@ function sync_upload ($photo, $title = null, $description = null, $tags = null,
foreach ($rsp as $line) {
if (preg_match('|<err code="([0-9]+)" msg="(.*)"|', $line, $match)) {
if ($this->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];
Expand All @@ -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");
}

}
Expand Down Expand Up @@ -486,7 +487,7 @@ function async_upload ($photo, $title = null, $description = null, $tags = null,
foreach ($rsp as $line) {
if (preg_match('/<err code="([0-9]+)" msg="(.*)"/', $line, $match)) {
if ($this->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];
Expand All @@ -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");
}
}

Expand Down Expand Up @@ -552,7 +553,7 @@ function replace ($photo, $photo_id, $async = null) {
foreach ($rsp as $line) {
if (preg_match('|<err code="([0-9]+)" msg="(.*)"|', $line, $match)) {
if ($this->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];
Expand All @@ -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");
}
}

Expand Down