forked from doraemonext/wechat-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
90 lines (61 loc) · 2.25 KB
/
exceptions.py
File metadata and controls
90 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import six
from wechat_sdk.utils import to_binary, to_text
class WechatException(Exception):
"""wechat-python-sdk 异常基类"""
pass
class WechatAPIException(WechatException):
"""官方 API 错误异常(必须包含错误码及错误信息)"""
def __init__(self, errcode, errmsg):
"""
:param errcode: 错误代码
:param errmsg: 错误信息
"""
self.errcode = errcode
self.errmsg = errmsg
def __str__(self):
if six.PY2:
return to_binary('{code}: {msg}'.format(code=self.errcode, msg=self.errmsg))
else:
return to_text('{code}: {msg}'.format(code=self.errcode, msg=self.errmsg))
class WechatSDKException(WechatException):
"""SDK 错误异常(仅包含错误内容描述)"""
def __init__(self, message=''):
"""
:param message: 错误内容描述,可选
"""
self.message = message
def __str__(self):
if six.PY2:
return to_binary(self.message)
else:
return to_text(self.message)
class NeedParamError(WechatSDKException):
"""构造参数提供不全异常"""
pass
class ParseError(WechatSDKException):
"""解析微信服务器数据异常"""
pass
class NeedParseError(WechatSDKException):
"""尚未解析微信服务器请求数据异常"""
pass
class OfficialAPIError(WechatAPIException):
"""微信官方API请求出错异常"""
def __init__(self, errcode, errmsg=None):
if errmsg is None: # 对旧版本 OfficialAPIError 的兼容代码
super(OfficialAPIError, self).__init__(99999, errmsg=errcode)
return
super(OfficialAPIError, self).__init__(errcode, errmsg)
class UnOfficialAPIError(WechatSDKException):
"""微信非官方API请求出错异常"""
pass
class NeedLoginError(UnOfficialAPIError):
"""微信非官方API请求出错异常 - 需要登录"""
pass
class LoginError(UnOfficialAPIError):
"""微信非官方API请求出错异常 - 登录出错"""
pass
class LoginVerifyCodeError(LoginError):
"""微信非官方API请求出错异常 - 登录出错 - 验证码错误"""
pass