Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
71a394c3
Commit
71a394c3
authored
Oct 10, 2013
by
Greg Price
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1301 from edx/gprice/forums-500
Make forums endpoints return better status codes
parents
369ea7fe
b60f5f80
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
14 deletions
+17
-14
lms/djangoapps/django_comment_client/forum/tests.py
+1
-1
lms/djangoapps/django_comment_client/forum/views.py
+6
-9
lms/djangoapps/django_comment_client/middleware.py
+2
-2
lms/djangoapps/django_comment_client/tests/test_middleware.py
+8
-2
No files found.
lms/djangoapps/django_comment_client/forum/tests.py
View file @
71a394c3
...
@@ -65,7 +65,7 @@ class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -65,7 +65,7 @@ class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase):
self
.
assertEqual
(
self
.
response
.
status_code
,
404
)
self
.
assertEqual
(
self
.
response
.
status_code
,
404
)
@patch
(
'student.models.cc.User.from_django_user'
)
@patch
(
'student.models.cc.User.from_django_user'
)
@patch
(
'student.models.cc.User.
active
_threads'
)
@patch
(
'student.models.cc.User.
subscribed
_threads'
)
def
test_user_followed_threads_exception
(
self
,
mock_threads
,
mock_from_django_user
):
def
test_user_followed_threads_exception
(
self
,
mock_threads
,
mock_from_django_user
):
# Mock the code that makes the HTTP requests to the cs_comment_service app
# Mock the code that makes the HTTP requests to the cs_comment_service app
...
...
lms/djangoapps/django_comment_client/forum/views.py
View file @
71a394c3
...
@@ -115,11 +115,8 @@ def inline_discussion(request, course_id, discussion_id):
...
@@ -115,11 +115,8 @@ def inline_discussion(request, course_id, discussion_id):
cc_user
=
cc
.
User
.
from_django_user
(
request
.
user
)
cc_user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user_info
=
cc_user
.
to_dict
()
user_info
=
cc_user
.
to_dict
()
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
):
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
):
# TODO (vshnayder): since none of this code seems to be aware of the fact that
# sometimes things go wrong, I suspect that the js client is also not
# checking for errors on request. Check and fix as needed.
log
.
error
(
"Error loading inline discussion threads."
)
log
.
error
(
"Error loading inline discussion threads."
)
raise
Http404
raise
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
...
@@ -180,7 +177,7 @@ def forum_form_discussion(request, course_id):
...
@@ -180,7 +177,7 @@ def forum_form_discussion(request, course_id):
return
render_to_response
(
'discussion/maintenance.html'
,
{})
return
render_to_response
(
'discussion/maintenance.html'
,
{})
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
)
as
err
:
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
)
as
err
:
log
.
error
(
"Error loading forum discussion threads:
%
s"
,
str
(
err
))
log
.
error
(
"Error loading forum discussion threads:
%
s"
,
str
(
err
))
raise
Http404
raise
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user_info
=
user
.
to_dict
()
user_info
=
user
.
to_dict
()
...
@@ -247,7 +244,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -247,7 +244,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
,
user_id
=
request
.
user
.
id
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
,
user_id
=
request
.
user
.
id
)
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
):
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
):
log
.
error
(
"Error loading single thread."
)
log
.
error
(
"Error loading single thread."
)
raise
Http404
raise
if
request
.
is_ajax
():
if
request
.
is_ajax
():
courseware_context
=
get_courseware_context
(
thread
,
course
)
courseware_context
=
get_courseware_context
(
thread
,
course
)
...
@@ -272,7 +269,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -272,7 +269,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
threads
.
append
(
thread
.
to_dict
())
threads
.
append
(
thread
.
to_dict
())
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
):
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
):
log
.
error
(
"Error loading single thread."
)
log
.
error
(
"Error loading single thread."
)
raise
Http404
raise
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'load_forum'
)
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'load_forum'
)
...
@@ -370,7 +367,7 @@ def user_profile(request, course_id, user_id):
...
@@ -370,7 +367,7 @@ def user_profile(request, course_id, user_id):
}
}
return
render_to_response
(
'discussion/user_profile.html'
,
context
)
return
render_to_response
(
'discussion/user_profile.html'
,
context
)
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
,
User
.
DoesNotExist
)
:
except
User
.
DoesNotExist
:
raise
Http404
raise
Http404
...
@@ -413,5 +410,5 @@ def followed_threads(request, course_id, user_id):
...
@@ -413,5 +410,5 @@ def followed_threads(request, course_id, user_id):
}
}
return
render_to_response
(
'discussion/user_profile.html'
,
context
)
return
render_to_response
(
'discussion/user_profile.html'
,
context
)
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
,
User
.
DoesNotExist
)
:
except
User
.
DoesNotExist
:
raise
Http404
raise
Http404
lms/djangoapps/django_comment_client/middleware.py
View file @
71a394c3
...
@@ -18,7 +18,7 @@ class AjaxExceptionMiddleware(object):
...
@@ -18,7 +18,7 @@ class AjaxExceptionMiddleware(object):
"""
"""
if
isinstance
(
exception
,
CommentClientError
)
and
request
.
is_ajax
():
if
isinstance
(
exception
,
CommentClientError
)
and
request
.
is_ajax
():
try
:
try
:
return
JsonError
(
json
.
loads
(
exception
.
message
))
return
JsonError
(
json
.
loads
(
exception
.
message
)
,
500
)
except
ValueError
:
except
ValueError
:
return
JsonError
(
exception
.
message
)
return
JsonError
(
exception
.
message
,
500
)
return
None
return
None
lms/djangoapps/django_comment_client/tests/test_middleware.py
View file @
71a394c3
...
@@ -20,8 +20,14 @@ class AjaxExceptionTestCase(TestCase):
...
@@ -20,8 +20,14 @@ class AjaxExceptionTestCase(TestCase):
self
.
request0
.
META
[
'HTTP_X_REQUESTED_WITH'
]
=
"SHADOWFAX"
self
.
request0
.
META
[
'HTTP_X_REQUESTED_WITH'
]
=
"SHADOWFAX"
def
test_process_exception
(
self
):
def
test_process_exception
(
self
):
self
.
assertIsInstance
(
self
.
a
.
process_exception
(
self
.
request1
,
self
.
exception1
),
middleware
.
JsonError
)
response1
=
self
.
a
.
process_exception
(
self
.
request1
,
self
.
exception1
)
self
.
assertIsInstance
(
self
.
a
.
process_exception
(
self
.
request1
,
self
.
exception2
),
middleware
.
JsonError
)
self
.
assertIsInstance
(
response1
,
middleware
.
JsonError
)
self
.
assertEqual
(
500
,
response1
.
status_code
)
response2
=
self
.
a
.
process_exception
(
self
.
request1
,
self
.
exception2
)
self
.
assertIsInstance
(
response2
,
middleware
.
JsonError
)
self
.
assertEqual
(
500
,
response2
.
status_code
)
self
.
assertIsNone
(
self
.
a
.
process_exception
(
self
.
request1
,
self
.
exception0
))
self
.
assertIsNone
(
self
.
a
.
process_exception
(
self
.
request1
,
self
.
exception0
))
self
.
assertIsNone
(
self
.
a
.
process_exception
(
self
.
request0
,
self
.
exception1
))
self
.
assertIsNone
(
self
.
a
.
process_exception
(
self
.
request0
,
self
.
exception1
))
self
.
assertIsNone
(
self
.
a
.
process_exception
(
self
.
request0
,
self
.
exception0
))
self
.
assertIsNone
(
self
.
a
.
process_exception
(
self
.
request0
,
self
.
exception0
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment