- libs: 新增 hr_sdk / hotel_report / dingtalk,更新 desktopauto - controlplane-next: SDK 管理模块(controller/entity/migrations)与前端视图 - electron-shell: 插件同步、注册表、runner 调整 - plugins: XQ0035/XQ0041/XQ0042/XQ0045_XQ0046/XQ0048/XQ0076/XQ0078 等版本更新 - tests/tools: 新增 SDK 兼容性检查与打包工具(sdk_pack.py、sdk_compat_check.py)
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""SDK 异常体系(契约见《SDK 挂载机制设计》§6.5)。
|
|
|
|
约定:
|
|
- 一律抛异常,**不 sys.exit / 不 KeyboardInterrupt**(旧脚本里的 SystemExit 在 SDK 中
|
|
全部改为 ``ConfigError`` / ``ApiError``,调用方按需捕获);
|
|
- 异常消息脱敏:不含 access_token / appSecret / webhook 的 access_token 段。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
class DingTalkError(Exception):
|
|
"""SDK 所有异常的基类。"""
|
|
|
|
|
|
class ConfigError(DingTalkError):
|
|
"""配置缺失/非法(缺少 app key、webhook 未配置、dws 未安装等)。"""
|
|
|
|
|
|
class NetworkError(DingTalkError):
|
|
"""网络层失败(超时、连接中断、5xx),重试后仍失败才抛出。"""
|
|
|
|
|
|
class AuthError(DingTalkError):
|
|
"""鉴权失败(appKey/appSecret 错误、access_token 失效)。"""
|
|
|
|
|
|
class ApiError(DingTalkError):
|
|
"""钉钉接口返回业务错误。
|
|
|
|
Attributes:
|
|
code: 钉钉错误码(新接口 ``code`` 或旧接口 ``errcode``),字符串形式。
|
|
errmsg: 原始错误描述。
|
|
payload: 原始响应体(便于排查,不含凭证)。
|
|
"""
|
|
|
|
def __init__(self, message: str, code: str = "", errmsg: str = "", payload=None):
|
|
super().__init__(message)
|
|
self.code = str(code or "")
|
|
self.errmsg = str(errmsg or "")
|
|
self.payload = payload
|
|
|
|
|
|
class DwsError(DingTalkError):
|
|
"""dws 命令行执行失败;``code`` 为上游 server_error_code(如 11056=会话不存在)。"""
|
|
|
|
def __init__(self, message: str, code: str = ""):
|
|
super().__init__(message)
|
|
self.code = str(code or "")
|
|
|
|
|
|
class CancelledError(DingTalkError):
|
|
"""调用方通过 ``should_cancel()`` 请求中止。"""
|
|
|
|
|
|
__all__ = [
|
|
"ApiError",
|
|
"AuthError",
|
|
"CancelledError",
|
|
"ConfigError",
|
|
"DingTalkError",
|
|
"DwsError",
|
|
"NetworkError",
|
|
]
|