From 13e5f26f1f91fa7a38b7b92fb14b684ee56d5646 Mon Sep 17 00:00:00 2001 From: "Malte S. Stretz" Date: Tue, 16 Aug 2011 16:28:21 +0200 Subject: [PATCH] Fix error handling. --- cloudfiles_http.php | 72 ++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/cloudfiles_http.php b/cloudfiles_http.php index 34c1288..0cddb12 100755 --- a/cloudfiles_http.php +++ b/cloudfiles_http.php @@ -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()); @@ -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); @@ -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; @@ -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); @@ -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; } @@ -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; } @@ -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;