From 91b43f2b524303605f29bc8612f0897ae866ad9e Mon Sep 17 00:00:00 2001 From: SwZ Date: Fri, 18 Apr 2025 17:26:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B4=A6=E5=8F=B7=E5=9B=9E?= =?UTF-8?q?=E6=8A=A5=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exceptions.py | 16 ++++++++++++++-- main.py | 6 +++--- spider/task.py | 8 ++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/exceptions.py b/exceptions.py index 672a0b8..d7aba0a 100644 --- a/exceptions.py +++ b/exceptions.py @@ -1,6 +1,18 @@ -class AuthException(Exception): +class BaseError(Exception): + def __init__(self, message='', error_type='failed'): + self.error_type = error_type + self.message = message + + def __str__(self): + return self.message + + def __repr__(self): + return self.message + + +class AuthException(BaseError): pass -class OperationFailed(Exception): +class OperationFailed(BaseError): pass diff --git a/main.py b/main.py index 78fa1fb..b4ff0d0 100644 --- a/main.py +++ b/main.py @@ -47,12 +47,12 @@ def execute_task(tid, task_type, **kwargs): try: result = TASK_TYPE.get(task_type)(**kwargs) task_callback(tid, data=result) - except AuthException as e: + except (AuthException, OperationFailed) as e: record_full_log(error_logger, e) - task_callback(tid, data={}, status='fail', msg=str(e)) + task_callback(tid, data={}, status=e.error_type, msg=str(e)) except Exception as e: record_full_log(error_logger, e) - task_callback(tid, data={}, status='fail', msg=str(e)) + task_callback(tid, data={}, status='failed', msg=str(e)) def main(): diff --git a/spider/task.py b/spider/task.py index d1c1f54..2692917 100644 --- a/spider/task.py +++ b/spider/task.py @@ -786,7 +786,7 @@ def check_account_status(page): # 账户被暂停 suspended_span = page.query_selector_all('//span[text()="We suspended your account"]') if suspended_span: - raise AuthException('该账户被暂停') + raise AuthException('该账户被暂停', 'frozen') except TimeoutError: pass @@ -794,7 +794,7 @@ def check_account_status(page): # 被封 lock_img = page.query_selector_all('//img[@src="/images/checkpoint/epsilon/comet/intro.png"]') if lock_img: - raise AuthException('该账户已被封禁') + raise AuthException('该账户已被封禁', 'frozen') except TimeoutError: pass @@ -802,10 +802,10 @@ def check_account_status(page): # 无法登录 无效cookies login_btn = page.query_selector_all('//button[@name="login"]') if login_btn: - raise AuthException('该账户登录状态失效') + raise AuthException('该账户登录状态失效', 'invalid') except TimeoutError: pass - raise AuthException('该账户异常') + raise AuthException('该账户异常', 'invalid') class RLock(threading._RLock):