1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-09-19 16:38:51 +02:00

Allow "PhutilAWSException" to identify "EBS: Not Found" errors

Summary: Ref T13630. Piledriver cares about EBS error specifics; expand this class a bit to expose more error information.

Test Plan: Created and destroyed resource piles with Piledriver control code, elsewhere.

Maniphest Tasks: T13630

Differential Revision: https://secure.phabricator.com/D21732
This commit is contained in:
epriestley 2021-05-30 00:17:53 -07:00
parent a028291f8e
commit 7cbdf37819
2 changed files with 43 additions and 3 deletions

View file

@ -49,4 +49,24 @@ final class PhutilAWSException extends Exception {
return $this->httpStatus;
}
public function isNotFoundError() {
if ($this->hasErrorCode('InvalidVolume.NotFound')) {
return true;
}
return false;
}
private function hasErrorCode($code) {
$errors = idx($this->params, 'Errors', array());
foreach ($errors as $error) {
if ($error[0] === $code) {
return true;
}
}
return false;
}
}

View file

@ -142,6 +142,7 @@ abstract class PhutilAWSFuture extends FutureProxy {
try {
$xml = @(new SimpleXMLElement($body));
} catch (Exception $ex) {
phlog($ex);
$xml = null;
}
@ -155,9 +156,28 @@ abstract class PhutilAWSFuture extends FutureProxy {
);
if ($xml) {
$params['RequestID'] = $xml->RequestID[0];
$errors = array($xml->Error);
foreach ($errors as $error) {
$params['Errors'][] = array($error->Code, $error->Message);
// NOTE: The S3 and EC2 APIs return slightly different error responses.
// 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),
);
}
}
}