27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
|
class JmErrorCode:
|
|||
|
SUCCESS = (10000, "请求成功")
|
|||
|
TEXT_RISK_NOT_PASS = (50412, "输入文本前审核未通过")
|
|||
|
POST_TEXT_RISK_NOT_PASS = (50413, "输入文本NER、IP、Blocklist等拦截")
|
|||
|
INTERNAL_ERROR = (50500, "输出视频审核未通过")
|
|||
|
API_CONCURRENT_LIMIT = (50430, "请求已达到API并发限制,请稍后重试")
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def get_by_code(code):
|
|||
|
"""根据错误码获取对应的错误信息元组"""
|
|||
|
for attr_name in dir(JmErrorCode):
|
|||
|
if not attr_name.startswith('_') and isinstance(getattr(JmErrorCode, attr_name), tuple):
|
|||
|
error_code, _ = getattr(JmErrorCode, attr_name)
|
|||
|
if error_code == code:
|
|||
|
return getattr(JmErrorCode, attr_name)
|
|||
|
return None
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def get_message_by_code(code):
|
|||
|
"""根据错误码获取错误消息"""
|
|||
|
error = JmErrorCode.get_by_code(code)
|
|||
|
return error[1] if error else "未知错误"
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def is_success(code):
|
|||
|
"""检查是否成功"""
|
|||
|
return code == JmErrorCode.SUCCESS[0]
|