1234567891011121314151617181920212223242526272829303132 |
- #!/usr/bin/env python3
- # encoding:utf-8
- from . import app
- from .constant import error_response
- class BizException(Exception):
- def __init__(self, message, status_code=400):
- super().__init__(message)
- self.message = message
- self.status_code = status_code
- @app.errorhandler(BizException)
- def handle_biz_exception(error):
- return error_response(msg=str(error), http_code=200)
- # Generic error handler for uncaught exceptions
- @app.errorhandler(Exception)
- def handle_generic_exception(error):
- return error_response(msg=str(error), http_code=500)
- # Specific error handler for 404 Not Found errors
- @app.errorhandler(404)
- def handle_404_error(error):
- return error_response(msg="Resource not found", http_code=404)
- # Specific error handler for 400 Bad Request errors
- @app.errorhandler(400)
- def handle_400_error(error):
- return error_response(msg="Bad Request", http_code=400)
|