Skip to content

Commit

Permalink
Merge pull request #9 from tioncico/master
Browse files Browse the repository at this point in the history
AliYunoss  完善异常类 对HTTPClient错误接管
  • Loading branch information
kiss291323003 authored Jan 11, 2020
2 parents 12804a2 + 31f34ae commit f5338a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/AliYun/Result/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ public function parseResponse()
$code = $this->retrieveErrorCode($this->rawResponse->getBody());
$message = $this->retrieveErrorMessage($this->rawResponse->getBody());
$body = $this->rawResponse->getBody();

$details = array(
'status' => $httpStatus,
'request-id' => $requestId,
'code' => $code,
'message' => $message,
'code' => $code??$this->rawResponse->getErrCode(),
'message' => $message??$this->rawResponse->getErrMsg(),
'body' => $body
);
throw new OssException($details);
Expand All @@ -118,13 +117,13 @@ public function parseResponse()
private function retrieveErrorMessage($body)
{
if (empty($body) || false === strpos($body, '<?xml')) {
return '';
return null;
}
$xml = simplexml_load_string($body);
if (isset($xml->Message)) {
return strval($xml->Message);
}
return '';
return null;
}

/**
Expand All @@ -136,13 +135,13 @@ private function retrieveErrorMessage($body)
private function retrieveErrorCode($body)
{
if (empty($body) || false === strpos($body, '<?xml')) {
return '';
return null;
}
$xml = simplexml_load_string($body);
if (isset($xml->Code)) {
return strval($xml->Code);
}
return '';
return null;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions tests/AliYun/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
'endpoint' => END_POINT,
]);
$client = new \EasySwoole\Oss\AliYun\OssClient($config);
$data = $client->signUrl(OSS_BUCKET,'oss-test.jpg');
var_dump($data);
// var_dump($client->listBuckets());
// $data = $client->signUrl(OSS_BUCKET,'oss-test.jpg');
// var_dump($data);
try{
var_dump($client->listBuckets());

}catch (\EasySwoole\Oss\AliYun\Core\OssException $throwable){
var_dump($throwable->getMessage());
var_dump($throwable->getErrorCode());
}


// $ossClient = new \OSS\OssClient(
Expand Down
2 changes: 1 addition & 1 deletion tests/QiNiu/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

$bucketManager = new \Qiniu\Storage\BucketManager($auth);
list($list, $error) = $bucketManager->buckets();
var_dump($list);
var_dump($list,$error);

0 comments on commit f5338a1

Please sign in to comment.