Commit cc7b2942 by Nate Hardison

Handle Heroku's 503 maintenance mode response

The LMS comment client previously would try to parse the response
as JSON, choke, and return a 500 to the client. Now, the LMS client
displays a message indicating that the forums are down for
maintenance.
parent 073c6d9a
...@@ -174,6 +174,9 @@ def forum_form_discussion(request, course_id): ...@@ -174,6 +174,9 @@ def forum_form_discussion(request, course_id):
try: try:
unsafethreads, query_params = get_threads(request, course_id) # This might process a search query unsafethreads, query_params = get_threads(request, course_id) # This might process a search query
threads = [utils.safe_content(thread) for thread in unsafethreads] threads = [utils.safe_content(thread) for thread in unsafethreads]
except (cc.utils.CommentClientMaintenanceError) as err:
log.warning("Forum is in maintenance mode")
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 Http404
......
...@@ -55,6 +55,9 @@ def perform_request(method, url, data_or_params=None, *args, **kwargs): ...@@ -55,6 +55,9 @@ def perform_request(method, url, data_or_params=None, *args, **kwargs):
if 200 < response.status_code < 500: if 200 < response.status_code < 500:
raise CommentClientError(response.text) raise CommentClientError(response.text)
# Heroku returns a 503 when an application is in maintenance mode
elif response.status_code == 503:
raise CommentClientMaintenanceError(response.text)
elif response.status_code == 500: elif response.status_code == 500:
raise CommentClientUnknownError(response.text) raise CommentClientUnknownError(response.text)
else: else:
...@@ -72,5 +75,9 @@ class CommentClientError(Exception): ...@@ -72,5 +75,9 @@ class CommentClientError(Exception):
return repr(self.message) return repr(self.message)
class CommentClientMaintenanceError(CommentClientError):
pass
class CommentClientUnknownError(CommentClientError): class CommentClientUnknownError(CommentClientError):
pass pass
<%inherit file="../main.html" />
<h1>We're sorry</h1>
<p>The forums are currently undergoing maintenance. We'll have them back up shortly!</p>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment