Commit 7cdf8e78 authored by 谢宇轩's avatar 谢宇轩

refactor: 调整默认返回值逻辑的处理范围

parent 07babe89
...@@ -238,44 +238,32 @@ class Application implements ClientInterface ...@@ -238,44 +238,32 @@ class Application implements ClientInterface
if ($response->getStatusCode() >= 500) { if ($response->getStatusCode() >= 500) {
if ($this->logger) { if ($this->logger) {
$this->logger->error("sdk error, paypal service fail", $context); $this->logger->error("sdk error, Upstream service fail", $context);
} }
throw new SdkException("SDK Upstream Failed", $request, $response, []); throw new ApplicationException("SDK Upstream Failed", $request, []);
} }
if (in_array($response->getStatusCode(), [404, 405])) { try {
$rpcResult = $this->option->handlingPolicy()->process($response);
} catch (GuiltyResultException $exception) {
// 没有通过预期判定,转化为 SDK Exception
$this->lastRequestContext['error_message'] = $exception->getMessage();
$this->lastRequestContext['error_detail'] = $exception->getOptions(); // 获取错误的详情
if ($this->logger) { if ($this->logger) {
$this->logger->error("sdk error, endpoint not found", $context); $this->logger->warning("Error", $this->lastRequestContext);
} }
throw new ApplicationException("Api Endpoint Not Found.", $request, []); throw new SdkException($exception->getMessage(), $request, $response, $exception->getOptions());
} } catch (UnknowResultException $exception) {
// 无法解析,转化为 Application Exception
$rpcResult = []; // 日志中保留 OUT PUT
$this->lastRequestContext['error_message'] = $exception->getMessage();
if ($response->getStatusCode() != 304) { $this->lastRequestContext['error_detail'] = $exception->getResult(); // 获取错误的详情
try { if ($this->logger) {
$rpcResult = $this->option->handlingPolicy()->process($response); $this->logger->error("sdk error, bad response content.", $this->lastRequestContext);
} catch (GuiltyResultException $exception) {
// 没有通过预期判定,转化为 SDK Exception
$this->lastRequestContext['error_message'] = $exception->getMessage();
$this->lastRequestContext['error_detail'] = $exception->getOptions(); // 获取错误的详情
if ($this->logger) {
$this->logger->warning("Error", $this->lastRequestContext);
}
throw new SdkException($exception->getMessage(), $request, $response, $exception->getOptions());
} catch (UnknowResultException $exception) {
// 无法解析,转化为 Application Exception
// 日志中保留 OUT PUT
$this->lastRequestContext['error_message'] = $exception->getMessage();
$this->lastRequestContext['error_detail'] = $exception->getResult(); // 获取错误的详情
if ($this->logger) {
$this->logger->error("sdk error, bad response content.", $this->lastRequestContext);
}
throw new ApplicationException("Content Format error.", $request, []);
} }
throw new ApplicationException("Content Format error.", $request, []);
} }
$version = $response->getHeader('ETag'); $version = $response->getHeader('ETag');
if (!empty($version)) { if (!empty($version)) {
$rpcResult = array_merge($rpcResult, [ $rpcResult = array_merge($rpcResult, [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment