errors.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. from openleadr.enums import STATUS_CODES
  2. class ProtocolError(Exception):
  3. pass
  4. class FingerprintMismatch(Exception):
  5. pass
  6. class HTTPError(Exception):
  7. def __init__(self, status=500, description=None):
  8. super().__init__()
  9. self.response_code = status
  10. self.response_description = description
  11. class OutOfSequenceError(ProtocolError):
  12. def __init__(self, description='OUT OF SEQUENCE'):
  13. super().__init__()
  14. self.response_code = STATUS_CODES.OUT_OF_SEQUENCE
  15. self.response_description = description
  16. class NotAllowedError(ProtocolError):
  17. def __init__(self, description='NOT ALLOWED'):
  18. super().__init__()
  19. self.response_code = STATUS_CODES.NOT_ALLOWED
  20. self.response_description = description
  21. class InvalidIdError(ProtocolError):
  22. def __init__(self, description='INVALID ID'):
  23. super().__init__()
  24. self.response_code = STATUS_CODES.INVALID_ID
  25. self.response_description = description
  26. class NotRecognizedError(ProtocolError):
  27. def __init__(self, description='NOT RECOGNIZED'):
  28. super().__init__()
  29. self.response_code = STATUS_CODES.NOT_RECOGNIZED
  30. self.response_description = description
  31. class InvalidDataError(ProtocolError):
  32. def __init__(self, description='INVALID DATA'):
  33. super().__init__()
  34. self.response_code = STATUS_CODES.INVALID_DATA
  35. self.response_description = description
  36. class ComplianceError(ProtocolError):
  37. def __init__(self, description='COMPLIANCE ERROR'):
  38. super().__init__()
  39. self.response_code = STATUS_CODES.COMPLIANCE_ERROR
  40. self.response_description = description
  41. class SignalNotSupportedError(ProtocolError):
  42. def __init__(self, description='SIGNAL NOT SUPPORTED'):
  43. super().__init__()
  44. self.response_code = STATUS_CODES.SIGNAL_NOT_SUPPORTED
  45. self.response_description = description
  46. class ReportNotSupportedError(ProtocolError):
  47. def __init__(self, description='REPORT NOT SUPPORTED'):
  48. super().__init__()
  49. self.response_code = STATUS_CODES.REPORT_NOT_SUPPORTED
  50. self.response_description = description
  51. class TargetMismatchError(ProtocolError):
  52. def __init__(self, description='TARGET MISMATCH'):
  53. super().__init__()
  54. self.response_code = STATUS_CODES.TARGET_MISMATCH
  55. self.response_description = description
  56. class NotRegisteredOrAuthorizedError(ProtocolError):
  57. def __init__(self, description='NOT REGISTERED OR AUTHORIZED'):
  58. super().__init__()
  59. self.response_code = STATUS_CODES.NOT_REGISTERED_OR_AUTHORIZED
  60. self.response_description = description
  61. class DeploymentError(ProtocolError):
  62. def __init__(self, description='DEPLOYMENT ERROR OR OTHER ERROR'):
  63. super().__init__()
  64. self.response_code = STATUS_CODES.DEPLOYMENT_ERROR_OR_OTHER_ERROR
  65. self.response_description = description