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.
This commit is contained in:
Nate Hardison
2013-05-17 15:35:14 -07:00
parent 073c6d9a79
commit cc7b2942ee
3 changed files with 13 additions and 0 deletions

View File

@@ -174,6 +174,9 @@ def forum_form_discussion(request, course_id):
try:
unsafethreads, query_params = get_threads(request, course_id) # This might process a search query
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:
log.error("Error loading forum discussion threads: %s" % str(err))
raise Http404

View File

@@ -55,6 +55,9 @@ def perform_request(method, url, data_or_params=None, *args, **kwargs):
if 200 < response.status_code < 500:
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:
raise CommentClientUnknownError(response.text)
else:
@@ -72,5 +75,9 @@ class CommentClientError(Exception):
return repr(self.message)
class CommentClientMaintenanceError(CommentClientError):
pass
class CommentClientUnknownError(CommentClientError):
pass

View File

@@ -0,0 +1,3 @@
<%inherit file="../main.html" />
<h1>We're sorry</h1>
<p>The forums are currently undergoing maintenance. We'll have them back up shortly!</p>