in alibabacloud-gateway-oss/php/src/Client.php [216:319]
public function modifyResponse($context, $attributeMap){
$request = $context->request;
$response = $context->response;
$bodyStr = null;
if (Utils::is4xx($response->statusCode) || Utils::is5xx($response->statusCode)) {
$bodyStr = Utils::readAsString($response->body);
if (!Utils::empty_($bodyStr)) {
$respMap = XML::parseXml($bodyStr, null);
$err = Utils::assertAsMap(@$respMap["Error"]);
throw new TeaError([
"code" => @$err["Code"],
"message" => @$err["Message"],
"data" => [
"statusCode" => $response->statusCode,
"requestId" => @$err["RequestId"],
"ecCode" => @$err["EC"],
"Recommend" => @$err["RecommendDoc"],
"hostId" => @$err["HostId"]
]
]);
}
else {
$headers = $response->headers;
$requestId = @$headers["x-oss-request-id"];
$ecCode = @$headers["x-oss-ec-code"];
throw new TeaError([
"code" => $response->statusCode,
"message" => null,
"data" => [
"statusCode" => $response->statusCode,
"requestId" => "" . $requestId . "",
"ecCode" => $ecCode
]
]);
}
}
$ctx = $attributeMap->key;
if (!Utils::isUnset($ctx)) {
if (!Utils::isUnset(@$ctx["crc"]) && !Utils::isUnset(@$response->headers["x-oss-hash-crc64ecma"]) && !StringUtil::equals(@$ctx["crc"], @$response->headers["x-oss-hash-crc64ecma"])) {
throw new TeaError([
"code" => "CrcNotMatched",
"data" => [
"clientCrc" => @$ctx["crc"],
"serverCrc" => @$response->headers["x-oss-hash-crc64ecma"]
]
]);
}
if (!Utils::isUnset(@$ctx["md5"]) && !Utils::isUnset(@$response->headers["content-md5"]) && !StringUtil::equals(@$ctx["md5"], @$response->headers["content-md5"])) {
throw new TeaError([
"code" => "MD5NotMatched",
"data" => [
"clientMD5" => @$ctx["md5"],
"serverMD5" => @$response->headers["content-md5"]
]
]);
}
}
if (!Utils::isUnset($response->body)) {
if (Utils::equalNumber($response->statusCode, 204)) {
Utils::readAsString($response->body);
}
else if (StringUtil::equals($request->bodyType, "xml")) {
$bodyStr = Utils::readAsString($response->body);
$response->deserializedBody = $bodyStr;
if (!Utils::empty_($bodyStr)) {
$result = XML::parseXml($bodyStr, null);
$list = MapUtil::keySet($result);
if (Utils::equalNumber(ArrayUtil::size($list), 1)) {
$tmp = @$list_[0];
try {
$response->deserializedBody = Utils::assertAsMap(@$result[$tmp]);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
$response->deserializedBody = $result;
}
}
}
}
else if (Utils::equalString($request->bodyType, "binary")) {
$response->deserializedBody = $response->body;
}
else if (Utils::equalString($request->bodyType, "byte")) {
$byt = Utils::readAsBytes($response->body);
$response->deserializedBody = $byt;
}
else if (Utils::equalString($request->bodyType, "string")) {
$response->deserializedBody = Utils::readAsString($response->body);
}
else if (Utils::equalString($request->bodyType, "json")) {
$obj = Utils::readAsJSON($response->body);
$res = Utils::assertAsMap($obj);
$response->deserializedBody = $res;
}
else if (Utils::equalString($request->bodyType, "array")) {
$response->deserializedBody = Utils::readAsJSON($response->body);
}
else {
$response->deserializedBody = Utils::readAsString($response->body);
}
}
}