Commit 8c8a49b5 authored by 谢宇轩's avatar 谢宇轩 😅

Merge branch '1.1' into 'master'

1.1

See merge request back-end/easy-http-sdk!13
parents d2faec26 659c7772
......@@ -16,7 +16,7 @@
],
"require": {
"php": ">7.2.5",
"psr/log": "^1.1",
"psr/log": "2.0",
"twig/twig": "^3.0",
"symfony/cache": "^5.4",
"yosymfony/toml": "^1.0",
......
......@@ -29,9 +29,6 @@ class Application implements ClientInterface
private const TOKEN_CACHE_KEY = "Auth.%s";
/** @var string jwtToken */
private $jwtToken = "";
/** @var Option $option */
private $option;
......@@ -158,28 +155,26 @@ class Application implements ClientInterface
$stack->push($middleware);
}
if ($request->authorization()) {
if ($this->jwtToken === "") {
try {
$this->jwtToken = $this->getAccessTokenFromCache();
} catch (CacheInvalidArgumentException $exception) {
// 缓存异常
throw new ApplicationException("auth cache error " . $exception->getMessage());
} catch (TransferException $exception) {
// 超时异常
if ($this->logger) {
$this->logger->error("sdk error, authorization timeout.");
}
throw new TimeOutExcetpion($request);
} catch (RuntimeException|InvalidArgumentException $exception) {
// 参数异常
if ($this->logger) {
$this->logger->error("sdk error, cause by:" . $exception->getMessage());
}
throw new ApplicationException($exception->getMessage(), $request, [], $exception);
try {
$jwtToken = $this->getAccessTokenFromCache();
$authMiddleware = $this->option->getAuthorizationMiddleware();
$stack->push(new $authMiddleware($jwtToken));
} catch (CacheInvalidArgumentException $exception) {
// 缓存异常
throw new ApplicationException("auth cache error " . $exception->getMessage());
} catch (TransferException $exception) {
// 超时异常
if ($this->logger) {
$this->logger->error("sdk error, authorization timeout.");
}
throw new TimeOutExcetpion($request);
} catch (RuntimeException|InvalidArgumentException $exception) {
// 参数异常
if ($this->logger) {
$this->logger->error("sdk error, cause by:" . $exception->getMessage());
}
throw new ApplicationException($exception->getMessage(), $request, [], $exception);
}
$authMiddleware = $this->option->getAuthorizationMiddleware();
$stack->push(new $authMiddleware($this->jwtToken));
}
}
......
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