biz_exception.py 829 B

123456789101112131415161718192021222324252627
  1. from typing import Optional, Dict, Any
  2. class BizException(Exception):
  3. def __init__(
  4. self,
  5. code: int,
  6. message: str,
  7. http_status: int = 400,
  8. extra: Optional[Dict[str, Any]] = None,
  9. ):
  10. self.code = code
  11. self.message = message
  12. self.http_status = http_status
  13. self.extra = extra
  14. class NotFoundError(BizException):
  15. def __init__(self, message="Resource not found"):
  16. super().__init__(code=40401, message=message, http_status=404)
  17. class PermissionDeniedError(BizException):
  18. def __init__(self, message="Permission denied"):
  19. super().__init__(code=40301, message=message, http_status=403)
  20. class BizLogicError(BizException):
  21. def __init__(self, message="Business logic error"):
  22. super().__init__(code=40001, message=message)