BatchDeleteMessageResponse.php
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace AliyunMNS\Responses;
use AliyunMNS\Constants;
use AliyunMNS\Exception\MnsException;
use AliyunMNS\Exception\QueueNotExistException;
use AliyunMNS\Exception\InvalidArgumentException;
use AliyunMNS\Exception\BatchDeleteFailException;
use AliyunMNS\Exception\ReceiptHandleErrorException;
use AliyunMNS\Responses\BaseResponse;
use AliyunMNS\Common\XMLParser;
use AliyunMNS\Model\DeleteMessageErrorItem;
class BatchDeleteMessageResponse extends BaseResponse
{
public function __construct()
{
}
public function parseResponse($statusCode, $content)
{
$this->statusCode = $statusCode;
if ($statusCode == 204) {
$this->succeed = TRUE;
} else {
$this->parseErrorResponse($statusCode, $content);
}
}
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
{
$this->succeed = FALSE;
$xmlReader = $this->loadXmlContent($content);
try {
while ($xmlReader->read())
{
if ($xmlReader->nodeType == \XMLReader::ELEMENT) {
switch ($xmlReader->name) {
case Constants::ERROR:
$this->parseNormalErrorResponse($xmlReader);
break;
default: // case Constants::Messages
$this->parseBatchDeleteErrorResponse($xmlReader);
break;
}
}
}
} catch (\Exception $e) {
if ($exception != NULL) {
throw $exception;
} elseif($e instanceof MnsException) {
throw $e;
} else {
throw new MnsException($statusCode, $e->getMessage());
}
} catch (\Throwable $t) {
throw new MnsException($statusCode, $t->getMessage());
}
}
private function parseBatchDeleteErrorResponse($xmlReader)
{
$ex = new BatchDeleteFailException($this->statusCode, "BatchDeleteMessage Failed For Some ReceiptHandles");
while ($xmlReader->read())
{
if ($xmlReader->nodeType == \XMLReader::ELEMENT && $xmlReader->name == Constants::ERROR) {
$ex->addDeleteMessageErrorItem( DeleteMessageErrorItem::fromXML($xmlReader));
}
}
throw $ex;
}
private function parseNormalErrorResponse($xmlReader)
{
$result = XMLParser::parseNormalError($xmlReader);
if ($result['Code'] == Constants::INVALID_ARGUMENT)
{
throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
}
if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
{
throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
}
if ($result['Code'] == Constants::RECEIPT_HANDLE_ERROR)
{
throw new ReceiptHandleErrorException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
}
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
}
}
?>