Changeset View
Changeset View
Standalone View
Standalone View
src/future/aws/PhutilAWSFuture.php
Show First 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | abstract class PhutilAWSFuture extends FutureProxy { | ||||
} | } | ||||
protected function didReceiveResult($result) { | protected function didReceiveResult($result) { | ||||
list($status, $body, $headers) = $result; | list($status, $body, $headers) = $result; | ||||
try { | try { | ||||
$xml = @(new SimpleXMLElement($body)); | $xml = @(new SimpleXMLElement($body)); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
phlog($ex); | |||||
$xml = null; | $xml = null; | ||||
} | } | ||||
if ($status->isError() || !$xml) { | if ($status->isError() || !$xml) { | ||||
if (!($status instanceof HTTPFutureHTTPResponseStatus)) { | if (!($status instanceof HTTPFutureHTTPResponseStatus)) { | ||||
throw $status; | throw $status; | ||||
} | } | ||||
$params = array( | $params = array( | ||||
'body' => $body, | 'body' => $body, | ||||
); | ); | ||||
if ($xml) { | if ($xml) { | ||||
$params['RequestID'] = $xml->RequestID[0]; | $params['RequestID'] = $xml->RequestID[0]; | ||||
$errors = array($xml->Error); | |||||
foreach ($errors as $error) { | // NOTE: The S3 and EC2 APIs return slightly different error responses. | ||||
$params['Errors'][] = array($error->Code, $error->Message); | |||||
// In S3 responses, there's a simple top-level "<Error>" element. | |||||
$s3_error = $xml->Error; | |||||
if ($s3_error) { | |||||
$params['Errors'][] = array( | |||||
phutil_string_cast($s3_error->Code), | |||||
phutil_string_cast($s3_error->Message), | |||||
); | |||||
} | |||||
// In EC2 responses, there's an "<Errors>" element with "<Error>" | |||||
// children. | |||||
$ec2_errors = $xml->Errors[0]; | |||||
if ($ec2_errors) { | |||||
foreach ($ec2_errors as $error) { | |||||
$params['Errors'][] = array( | |||||
phutil_string_cast($error->Code), | |||||
phutil_string_cast($error->Message), | |||||
); | |||||
} | |||||
} | } | ||||
} | } | ||||
throw new PhutilAWSException($status->getStatusCode(), $params); | throw new PhutilAWSException($status->getStatusCode(), $params); | ||||
} | } | ||||
return $xml; | return $xml; | ||||
} | } | ||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0