mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 17:07:49 +08:00
feat : jwt
Some checks are pending
Build Docker / build (push) Waiting to run
Some checks are pending
Build Docker / build (push) Waiting to run
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Exception\Handler;
|
||||
|
||||
use App\Constants\ResultCode;
|
||||
use App\Exception\ErrException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@@ -30,17 +31,24 @@ class JwtExceptionHandler extends BaseErrExceptionHandler
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function modifyException(Throwable $e): Throwable
|
||||
protected function modifyException(JWTException $e): Throwable
|
||||
{
|
||||
// 根据不同的异常类型设置不同的code和message
|
||||
switch ($e->getMessage()) {
|
||||
case 'The token is expired':
|
||||
$e->code = ResultCode::JWT_EXPIRED;
|
||||
$e->message = 'token已过期';
|
||||
$code = ResultCode::JWT_EXPIRED;
|
||||
$message = 'token已过期';
|
||||
break;
|
||||
default:
|
||||
$e->code = ResultCode::JWT_ERROR;
|
||||
$e->message = 'token错误';
|
||||
$code = ResultCode::JWT_ERROR;
|
||||
$message = 'token错误';
|
||||
}
|
||||
|
||||
if (method_exists($e, 'setCustomCode')) {
|
||||
$e->setCustomCode($code);
|
||||
}
|
||||
if (method_exists($e, 'setCustomMessage')) {
|
||||
$e->setCustomMessage($message);
|
||||
}
|
||||
|
||||
return $e;
|
||||
|
||||
Reference in New Issue
Block a user