mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 20:27: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;
|
||||
|
||||
@@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
return [
|
||||
'handler' => [
|
||||
'http' => [
|
||||
@@ -16,6 +17,7 @@ return [
|
||||
App\Exception\Handler\ErrExceptionHandler::class,
|
||||
App\Exception\Handler\ValidationExceptionHandler::class,
|
||||
App\Exception\Handler\AppExceptionHandler::class,
|
||||
App\Exception\Handler\JwtExceptionHandler::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user