handler.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from misago.views import exceptions
  2. def is_misago_exception(exception):
  3. return exception.__class__ in exceptions.MISAGO_EXCEPTIONS
  4. def handle_http404_exception(request, exception):
  5. raise NotImplementedError()
  6. def handle_outdated_url_exception(request, exception):
  7. raise NotImplementedError()
  8. def handle_permission_denied_exception(request, exception):
  9. raise NotImplementedError()
  10. EXCEPTION_HANDLERS = (
  11. (exceptions.Http404, handle_http404_exception),
  12. (exceptions.OutdatedUrl, handle_outdated_url_exception),
  13. (exceptions.PermissionDenied, handle_permission_denied_exception),
  14. )
  15. def get_exception_handler(exception):
  16. for exception_type, handler in EXCEPTION_HANDLERS:
  17. if isinstance(exception, exception_type):
  18. return handler
  19. else:
  20. raise ValueError(
  21. "%s is not Misago exception" % exception.__class__.__name__)
  22. def handle_misago_exception(request, exception):
  23. handler = get_exception_handler(exception)
  24. return handler(request, exception)