exceptionhandler.py 657 B

1234567891011121314151617181920
  1. from rest_framework.views import exception_handler as rest_exception_handler
  2. from django.core.exceptions import PermissionDenied
  3. from django.utils import six
  4. from misago.core.exceptions import Banned
  5. def handle_api_exception(exception, context):
  6. response = rest_exception_handler(exception, context)
  7. if response:
  8. if isinstance(exception, Banned):
  9. response.data = exception.ban.get_serialized_message()
  10. elif isinstance(exception, PermissionDenied) and exception.args:
  11. response.data = {
  12. 'detail': six.text_type(exception),
  13. }
  14. return response
  15. else:
  16. return None