123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- # -*- coding: utf-8 -*-
- """
- wechatbase.exceptions
- ~~~~~~~~~~~~~~~~~~~~
- Basic exceptions definition.
- :copyright: (c) 2014 by messense.
- :license: MIT, see LICENSE for more details.
- """
- from __future__ import absolute_import, unicode_literals
- import six
- from typing import Optional
- from library import to_text, to_binary
- class WeChatException(Exception):
- def __init__(self, errCode, errMsg, client = None,
- request = None, response = None):
- super(WeChatException, self).__init__(errMsg)
- self.errCode = errCode
- self.errMsg = errMsg
- self.client = client
- self.request = request
- self.response = response
- def __str__(self):
- if self.client:
- _repr = '{kclass}(client: {client}, errCode: {errCode}, errMsg: {errMsg})'.format(
- kclass = self.__class__.__name__,
- client = repr(self.client),
- errCode = self.errCode,
- errMsg = self.errMsg)
- else:
- _repr = '{kclass}(errCode: {errCode}, errMsg: {errMsg})'.format(
- kclass = self.__class__.__name__,
- errCode = self.errCode,
- errMsg = self.errMsg)
- if six.PY2:
- return to_binary(_repr)
- else:
- return to_text(_repr)
- def __repr__(self):
- return str(self)
- @property
- def tip(self):
- return '{}({})'.format(self.errMsg, self.errCode)
- class InvalidSignatureException(WeChatException):
- """Invalid signature exception class"""
- def __init__(self, errCode = -40001, errMsg = 'Invalid signature', client = None):
- super(InvalidSignatureException, self).__init__(
- errCode = errCode,
- errMsg = errMsg,
- client = client)
- class APILimitedException(WeChatException):
- """WeChat API call limited exception class"""
- pass
- class InvalidAppIdException(WeChatException):
- """Invalid app_id exception class"""
- def __init__(self, errCode = -40005, errMsg = 'Invalid AppId', client = None):
- super(InvalidAppIdException, self).__init__(
- errCode = errCode,
- errMsg = errMsg,
- client = client)
- class WeChatOAuthException(WeChatException):
- """WeChat OAuth API exception class"""
- pass
- class WechatOAuthDummyException(WeChatException):
- def __init__(self, errCode = -40006, errMsg = 'Dummy OAuth', client = None):
- super(WechatOAuthDummyException, self).__init__(
- errCode = errCode,
- errMsg = errMsg,
- client = client)
- class WeChatComponentOAuthException(WeChatException):
- """WeChat Component OAuth API exception class"""
- pass
- class WechatValidationError(WeChatException):
- def __init__(self, errmsg, lvalue, rvalue, client = None):
- # type: (basestring, basestring, basestring, Optional[object])->None
- _errMsg = '{}({} != {})'.format(errmsg, lvalue, rvalue)
- super(WechatValidationError, self).__init__(errCode = -102,
- errMsg = _errMsg,
- client = client)
- class WechatNetworkException(WeChatException):
- pass
- class WeChatPayException(WeChatException):
- """WeChat Pay API exception class"""
- pass
|