exceptions.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. from apps.web.exceptions import UserServerException
  4. class ParameterError(UserServerException):
  5. pass
  6. class DeviceNetworkTimeoutError(Exception):
  7. pass
  8. class UartTimeoutError(Exception):
  9. pass
  10. class NotConnectError(Exception):
  11. pass
  12. class StartDeviceError(Exception):
  13. def __init__(self, device_rst = None):
  14. self.device_rst = device_rst
  15. super(StartDeviceError, self).__init__()
  16. def __str__(self):
  17. if self.device_rst:
  18. return u'启动设备失败({}),您支付的金币已经退还到您的账户。'.format(self.device_rst)
  19. else:
  20. return u'启动设备失败,您支付的金币已经退还到您的账户。'
  21. def __repr__(self):
  22. return 'main board error<{}>'.format(self.device_rst)
  23. class MessageSenderException(Exception):
  24. def __init__(self, exception):
  25. self.exception = exception
  26. super(MessageSenderException, self).__init__()
  27. def __repr__(self):
  28. return 'message sender error<{}>'.format(self.exception)
  29. class MqttConnectError(Exception):
  30. pass
  31. class MqttSubscribeError(Exception):
  32. pass
  33. class MqttPublishError(Exception):
  34. pass
  35. class StartDeviceCommuationException(Exception):
  36. def __init__(self, rst):
  37. self.rst = rst
  38. super(StartDeviceCommuationException, self).__init__()
  39. def __str__(self):
  40. return u'启动设备失败({}),您支付的金币已经退还到您的账户。'.format(self.rst)
  41. def __repr__(self):
  42. return 'module error<{}>'.format(self.rst)
  43. class ReportProxyError(Exception):
  44. pass
  45. class ReportProxyTypeError(Exception):
  46. pass
  47. class ReportProxyValueError(Exception):
  48. pass
  49. class ServiceException(UserServerException):
  50. _default_result = {"result": 2, "description": u"使用故障"}
  51. def __init__(self, result = None):
  52. self.result = result or self._default_result
  53. super(ServiceException, self).__init__()
  54. def __str__(self):
  55. return repr(self.result)
  56. class ClientServiceTimeOutException(ServiceException):
  57. _default_result = {"result": 2, "description": u"此设备网络超时,请您稍后再试,或更换机器重新扫码,谢谢!"}
  58. class ClientServiceSerialException(ServiceException):
  59. _default_result = {"result": 2, "description": u"此设备正忙,请更换机器重新扫码,谢谢!"}
  60. class ManagerServiceTimeOutException(ServiceException):
  61. _default_result = {"result": 2, "description": u"此设备离线,请稍后再试,或将天线置于机器外部,重新上电试试!"}
  62. class ManagerServiceSerialException(ServiceException):
  63. _default_result = {"result": 2, "description": u"此设备串口故障,请调整设备串口线重新上电试试!"}
  64. class DeviceNotExistException(UserServerException):
  65. def __init__(self):
  66. super(DeviceNotExistException, self).__init__()
  67. def __str__(self):
  68. return repr(u'设备不存在')
  69. class InvalidFileSize(UserServerException):
  70. def __init__(self, message, limit):
  71. super(InvalidFileSize, self).__init__(message)
  72. self.limit = limit
  73. class InvalidFileName(UserServerException):
  74. pass
  75. class InvalidPermission(UserServerException):
  76. pass
  77. class InvalidChildClass(UserServerException):
  78. pass
  79. class InvalidParameter(UserServerException):
  80. pass
  81. class ImproperlyConfigured(UserServerException):
  82. pass
  83. class FormatError(UserServerException):
  84. pass
  85. class EmptyInput(UserServerException):
  86. pass
  87. class UpdateError(UserServerException):
  88. """当模型更新失败的时候抛出"""
  89. pass
  90. class InsufficientFundsError(Exception):
  91. pass
  92. class TestError(UserServerException):
  93. _default_result = {"description": u"测试故障"}
  94. def __init__(self, result = None):
  95. self._result = result or self._default_result
  96. super(TestError, self).__init__()
  97. def __str__(self):
  98. return self._result.get("description", "")
  99. class TestTimeOutError(TestError):
  100. _default_result = {"description": u"测试串口超时故障"}
  101. class TestSerialError(TestError):
  102. _default_result = {"description": u"测试串口通信故障"}
  103. class MerchantError(Exception):
  104. pass
  105. class JOSError(Exception):
  106. pass
  107. class RentDeviceError(Exception):
  108. pass
  109. class NoDeviceFound(UserServerException):
  110. def __init__(self, dev_no):
  111. self.dev_no = dev_no
  112. def __repr__(self):
  113. return 'device({}) not found'.format(self.dev_no)
  114. def __str__(self):
  115. return repr(self)
  116. class NoGroupFound(UserServerException):
  117. def __init__(self, group_id):
  118. self.group_id = group_id
  119. def __repr__(self):
  120. return 'group({}) not found'.format(self.group_id)
  121. def __str__(self):
  122. return repr(self)
  123. class NoAgentFound(UserServerException):
  124. def __init__(self, agent_id):
  125. self.agent_id = agent_id
  126. def __repr__(self):
  127. return 'agent(id={}) not found'.format(self.agent_id)
  128. def __str__(self):
  129. return repr(self)
  130. class NoManagerFound(UserServerException):
  131. def __init__(self, manager_id):
  132. self.manager_id = manager_id
  133. def __repr__(self):
  134. return 'manager(id={}) not found'.format(self.manager_id)
  135. def __str__(self):
  136. return repr(self)
  137. class ImproperlyOperatedBalance(UserServerException):
  138. pass
  139. class WithdrawError(UserServerException):
  140. pass
  141. class OrderCheckError(UserServerException):
  142. pass
  143. class InterceptException(UserServerException):
  144. def __init__(self, redirect):
  145. self.redirect = redirect