from mdrsclient.api.user import UserApi from mdrsclient.exceptions import UnauthorizedException from mdrsclient.session import MDRSSession def token_check(session: MDRSSession) -> None: if session.token is not None: if session.token.is_refresh_required: user_api = UserApi(session) try: session.token = user_api.refresh(session.token) except UnauthorizedException: session.logout() elif session.token.is_expired: session.logout()