fixed bug

This commit is contained in:
yanwenwu
2020-05-19 08:22:48 +08:00
parent 9da4072b30
commit 64ce1243b4
3 changed files with 23 additions and 2 deletions

View File

@@ -4,6 +4,11 @@ namespace app;
// 应用请求对象类
use catcher\CatchAuth;
use catcher\Code;
use catcher\exceptions\FailedException;
use thans\jwt\exception\TokenBlacklistException;
use thans\jwt\exception\TokenExpiredException;
use thans\jwt\exception\TokenInvalidException;
class Request extends \think\Request
{
@@ -21,6 +26,21 @@ class Request extends \think\Request
$this->auth = new CatchAuth;
}
return $this->auth->user();
try {
$user = $this->auth->user();
} catch (\Exception $e) {
if ($e instanceof TokenExpiredException) {
throw new FailedException('token 过期', Code::LOGIN_EXPIRED);
}
if ($e instanceof TokenBlacklistException) {
throw new FailedException('token 被加入黑名单', Code::LOGIN_BLACKLIST);
}
if ($e instanceof TokenInvalidException) {
throw new FailedException('token 不合法', Code::LOST_LOGIN);
}
throw new FailedException('auth failed', Code::LOST_LOGIN);
}
return $user;
}
}