mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 19:27:48 +08:00
fix : jwt
This commit is contained in:
@@ -11,4 +11,23 @@ class ErrException extends ServerException
|
||||
* @var int
|
||||
*/
|
||||
protected $code = ResultCode::ERROR;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $data = [];
|
||||
|
||||
public function __construct(string $message = "", int $code = 0, array $data = [], ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ abstract class BaseErrExceptionHandler extends ExceptionHandler
|
||||
* @var AdminReturn|ApiReturn $returnObj
|
||||
*/
|
||||
$returnObj = $this->container->get($returnClass);
|
||||
$result = $returnObj->error($e->getMessage(), $e->getCode());
|
||||
$result = $returnObj->error($e->getMessage(), $e->getCode(), $e?->getData() ?? []);
|
||||
$this->stopPropagation();
|
||||
return $response->withHeader("Content-Type", "application/json")
|
||||
->withStatus(200)
|
||||
|
||||
@@ -31,7 +31,11 @@ class JwtExceptionHandler extends BaseErrExceptionHandler
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function modifyException(JWTException $e): Throwable
|
||||
/**
|
||||
* @param JWTException $e
|
||||
* @return ErrException
|
||||
*/
|
||||
protected function modifyException(JWTException $e): ErrException
|
||||
{
|
||||
// 根据不同的异常类型设置不同的code和message
|
||||
switch ($e->getMessage()) {
|
||||
@@ -51,7 +55,7 @@ class JwtExceptionHandler extends BaseErrExceptionHandler
|
||||
$e->setCustomMessage($message);
|
||||
}
|
||||
|
||||
return $e;
|
||||
return New ErrException($message,$code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user