diff --git a/lms/djangoapps/django_comment_client/middleware.py b/lms/djangoapps/django_comment_client/middleware.py new file mode 100644 index 0000000000..08e20b0296 --- /dev/null +++ b/lms/djangoapps/django_comment_client/middleware.py @@ -0,0 +1,9 @@ +from comment_client import CommentClientError +from django_comment_client.utils import JsonError +import json + +class AjaxExceptionMiddleware(object): + def process_exception(self, request, exception): + if isinstance(exception, CommentClientError) and request.is_ajax(): + return JsonError(json.loads(exception.message)) + return None