Skip to content

Commit

Permalink
Fix error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
mss committed Aug 16, 2011
1 parent 7866eb3 commit 13e5f26
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions cloudfiles_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function list_cdn_containers($enabled_only)
}
if (!$return_code) {
$this->error_str .= ": Failed to obtain valid HTTP response.";
array(0,$this->error_str,array());
return array(0,$this->error_str,array());
}
if ($return_code == 401) {
return array($return_code,"Unauthorized",array());
Expand Down Expand Up @@ -514,7 +514,7 @@ function head_account()

if (!$return_code) {
$this->error_str .= ": Failed to obtain valid HTTP response.";
array(0,$this->error_str,0,0);
return array(0,$this->error_str,0,0);
}
if ($return_code == 404) {
return array($return_code,"Account not found.",0,0);
Expand Down Expand Up @@ -559,16 +559,19 @@ function delete_container($container_name)
$url_path = $this->_make_path("STORAGE", $container_name);
$return_code = $this->_send_request("DEL_POST",$url_path,array(),"DELETE");

if (!$return_code) {
$this->error_str .= ": Failed to obtain valid HTTP response.";
}
if ($return_code == 409) {
switch ($return_code) {
case 204:
break;
case 0:
$this->error_str .= ": Failed to obtain valid HTTP response.";;
break;
case 409:
$this->error_str = "Container must be empty prior to removing it.";
}
if ($return_code == 404) {
break;
case 404:
$this->error_str = "Specified container did not exist to delete.";
}
if ($return_code != 204) {
break;
default:
$this->error_str = "Unexpected HTTP return code: $return_code.";
}
return $return_code;
Expand Down Expand Up @@ -704,7 +707,7 @@ function head_container($container_name)

if (!$return_code) {
$this->error_str .= ": Failed to obtain valid HTTP response.";
array(0,$this->error_str,0,0);
return array(0,$this->error_str,0,0);
}
if ($return_code == 404) {
return array($return_code,"Container not found.",0,0);
Expand Down Expand Up @@ -865,15 +868,19 @@ function update_object(&$obj)

$hdrs = $this->_metadata_headers($obj);
$return_code = $this->_send_request("DEL_POST",$url_path,$hdrs,"POST");
if (!$return_code) {
switch ($return_code) {
case 202:
break;
case 0:
$this->error_str .= ": Failed to obtain valid HTTP response.";
return 0;
}
if ($return_code == 404) {
$return_code = 0;
break;
case 404:
$this->error_str = "Account, Container, or Object not found.";
}
if ($return_code != 202) {
break;
default:
$this->error_str = "Unexpected HTTP return code: $return_code";
break;
}
return $return_code;
}
Expand Down Expand Up @@ -956,17 +963,19 @@ function copy_object($src_obj_name, $dest_obj_name, $container_name_source, $con
self::_process_metadata($hdrs,$metadata);

$return_code = $this->_send_request($conn_type,$url_path,$hdrs,"COPY");
if (!$return_code) {
switch ($return_code) {
case 201:
break;
case 0:
$this->error_str .= ": Failed to obtain valid HTTP response.";
return 0;
}
if ($return_code == 404) {
$return_code = 0;
break;
case 404:
$this->error_str = "Specified container/object did not exist.";
}
if ($return_code != 201) {
break;
default:
$this->error_str = "Unexpected HTTP return code: $return_code.";
}

return $return_code;
}

Expand All @@ -991,14 +1000,17 @@ function delete_object($container_name, $object_name)

$url_path = $this->_make_path("STORAGE", $container_name,$object_name);
$return_code = $this->_send_request("DEL_POST",$url_path,NULL,"DELETE");
if (!$return_code) {
switch ($return_code) {
case 204:
break;
case 0:
$this->error_str .= ": Failed to obtain valid HTTP response.";
return 0;
}
if ($return_code == 404) {
$return_code = 0;
break;
case 404:
$this->error_str = "Specified container did not exist to delete.";
}
if ($return_code != 204) {
break;
default:
$this->error_str = "Unexpected HTTP return code: $return_code.";
}
return $return_code;
Expand Down

0 comments on commit 13e5f26

Please sign in to comment.