assertArraySubset($expected, $result);
if (is_null($expectedParsedType)) {
$this->assertNull($result['parsed']);
} else {
$this->assertInstanceOf($expectedParsedType, $result['parsed']);
}
}
public function errorResponsesProvider()
{
$ec2Service = $this->generateTestService('ec2');
$ec2Client = $this->generateTestClient($ec2Service);
$ec2Command = $ec2Client->getCommand('TestOperation', []);
$queryService = $this->generateTestService('query');
$queryClient = $this->generateTestClient($queryService);
$queryCommand = $queryClient->getCommand('TestOperation', []);
$restXmlService = $this->generateTestService('query');
$restXmlClient = $this->generateTestClient($restXmlService);
$restXmlCommand = $restXmlClient->getCommand('TestOperation', []);
return [
// ec2, modeled exception
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'' . "\n" .
'' .
' ' .
' ' .
' TestException
' .
' Error Message' .
' SomeString' .
' 456' .
' ' .
' ' .
' xyz' .
'',
$ec2Command,
new XmlErrorParser($ec2Service),
[
'type' => 'client',
'request_id' => 'xyz',
'code' => 'TestException',
'message' => 'Error Message',
'body' => [
'TestHeaderMember' => 'foo-header',
'TestHeaders' => [
'foo' => 'foo-meta',
'bar' => 'bar-meta',
],
'TestStatus' => 400,
'TestString' => 'SomeString',
'TestInt' => 456
],
],
'SimpleXMLElement',
],
// ec2, no modeled shape
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'' . "\n" .
'' .
' ' .
' ' .
' NonExistentException
' .
' Error Message' .
' SomeString' .
' 456' .
' ' .
' ' .
' xyz' .
'',
$ec2Command,
new XmlErrorParser($ec2Service),
[
'type' => 'client',
'request_id' => 'xyz',
'code' => 'NonExistentException',
'message' => 'Error Message',
],
'SimpleXMLElement',
],
// query, modeled exception
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'' .
' ' .
' ErrorType' .
' TestException
' .
' Error Message' .
' SomeString' .
' 456' .
' ' .
' xyz' .
'',
$queryCommand,
new XmlErrorParser($queryService),
[
'type' => 'client',
'request_id' => 'xyz',
'code' => 'TestException',
'message' => 'Error Message',
'body' => [
'TestHeaderMember' => 'foo-header',
'TestHeaders' => [
'foo' => 'foo-meta',
'bar' => 'bar-meta',
],
'TestStatus' => 400,
'TestString' => 'SomeString',
'TestInt' => 456
],
],
'SimpleXMLElement',
],
// query, no modeled shape
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'' .
' ' .
' ErrorType' .
' NonExistentException
' .
' Error Message' .
' SomeString' .
' 456' .
' ' .
' xyz' .
'',
$queryCommand,
new XmlErrorParser($queryService),
[
'type' => 'client',
'request_id' => 'xyz',
'code' => 'NonExistentException',
'message' => 'Error Message',
],
'SimpleXMLElement',
],
// rest-xml, modeled exception
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'' .
' ' .
' ErrorType' .
' TestException
' .
' Error Message' .
' SomeString' .
' 456' .
' ' .
' xyz' .
'',
$restXmlCommand,
new XmlErrorParser($restXmlService),
[
'type' => 'client',
'request_id' => 'xyz',
'code' => 'TestException',
'message' => 'Error Message',
'body' => [
'TestHeaderMember' => 'foo-header',
'TestHeaders' => [
'foo' => 'foo-meta',
'bar' => 'bar-meta',
],
'TestStatus' => 400,
'TestString' => 'SomeString',
'TestInt' => 456
],
],
'SimpleXMLElement',
],
// rest-xml, no modeled shape
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'' .
' ' .
' ErrorType' .
' NonExistentException
' .
' Error Message' .
' SomeString' .
' 456' .
' ' .
' xyz' .
'',
$restXmlCommand,
new XmlErrorParser($restXmlService),
[
'type' => 'client',
'request_id' => 'xyz',
'code' => 'NonExistentException',
'message' => 'Error Message',
],
'SimpleXMLElement',
],
// S3 format, modeled exception
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n\r\n" .
'' .
' ErrorType' .
' TestException
' .
' Error Message' .
' xyz' .
' Foo' .
' SomeString' .
' 456' .
' baz' .
'',
$restXmlCommand,
new XmlErrorParser($restXmlService),
[
'type' => 'client',
'request_id' => 'xyz',
'code' => 'TestException',
'message' => 'Error Message',
'body' => [
'TestHeaderMember' => 'foo-header',
'TestHeaders' => [
'foo' => 'foo-meta',
'bar' => 'bar-meta',
],
'TestStatus' => 400,
'TestString' => 'SomeString',
'TestInt' => 456
],
],
'SimpleXMLElement',
],
// S3 format, no modeled shape
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n\r\n" .
'' .
' ErrorType' .
' NonExistentException
' .
' Error Message' .
' xyz' .
' Foo' .
' SomeString' .
' 456' .
' baz' .
'',
$restXmlCommand,
new XmlErrorParser($restXmlService),
[
'type' => 'client',
'request_id' => 'xyz',
'code' => 'NonExistentException',
'message' => 'Error Message',
],
'SimpleXMLElement',
],
// S3 format, empty body, request id in header
[
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
"x-meta-bar: bar-meta\r\n" .
"x-amz-request-id: xyz\r\n\r\n",
$restXmlCommand,
new XmlErrorParser($restXmlService),
[
'type' => 'client',
'request_id' => 'xyz',
'body' => [],
],
null
],
];
}
public function testParsesResponsesWithNoBodyAndNoRequestId()
{
$response = Psr7\Message::parseResponse(
"HTTP/1.1 400 Bad Request\r\n\r\n"
);
$parser = new XmlErrorParser();
$result = $parser($response);
$this->assertSame('400 Bad Request', $result['message']);
$this->assertNull($result['parsed']);
}
public function testParsesResponsesWithNoBody()
{
$response = $response = Psr7\Message::parseResponse(
"HTTP/1.1 400 Bad Request\r\nX-Amz-Request-ID: Foo\r\n\r\n"
);
$parser = new XmlErrorParser();
$result = $parser($response);
$this->assertSame('400 Bad Request (Request-ID: Foo)', $result['message']);
$this->assertSame('Foo', $result['request_id']);
}
public function testUsesNotFoundWhen404()
{
$response = $response = Psr7\Message::parseResponse(
"HTTP/1.1 404 Not Found\r\nX-Amz-Request-ID: Foo\r\n\r\n"
);
$parser = new XmlErrorParser();
$result = $parser($response);
$this->assertSame('NotFound', $result['code']);
}
}