modifyException($throwable); // 传递给基类处理 return $this->handlerResponse($throwable, $response); } return $response; } protected function modifyException(Throwable $e): Throwable { // 根据不同的异常类型设置不同的code和message switch ($e->getMessage()) { case 'The token is expired': $e->code = ResultCode::JWT_EXPIRED; $e->message = 'token已过期'; break; default: $e->code = ResultCode::JWT_ERROR; $e->message = 'token错误'; } return $e; } /** * @param Throwable $throwable * @return bool */ public function isValid(Throwable $throwable): bool { return $throwable instanceof JWTException; } }