Display the appropriate type of error message depending on the type of the incoming request
This commit is contained in:
@@ -227,7 +227,15 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
|
||||
ajax_url = settings.MITX_ROOT_URL + '/modx/'+module+'/'+id+'/'
|
||||
|
||||
# Grab the XML corresponding to the request from course.xml
|
||||
xml = content_parser.module_xml(request.user, module, 'id', id)
|
||||
try:
|
||||
xml = content_parser.module_xml(request.user, module, 'id', id)
|
||||
except:
|
||||
record_exception(log, "Unable to load module during ajax call")
|
||||
if 'text/html' in request.accepted_types:
|
||||
return render_to_response("module-error.html", {})
|
||||
else:
|
||||
response = HttpResponse(json.dumps({'success': "We're sorry, this module is temporarily unavailable. Our staff is working to fix it as soon as possible"}))
|
||||
return response
|
||||
|
||||
# Create the module
|
||||
system = I4xSystem(track_function = make_track_function(request),
|
||||
@@ -242,8 +250,11 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
|
||||
id,
|
||||
state=oldstate)
|
||||
except:
|
||||
record_exception(log, "Unable to load module during ajax call")
|
||||
response = HttpResponse(json.dumps({'success': "We're sorry, this module is temporarily unavailable. Our staff is working to fix it as soon as possible"}))
|
||||
record_exception(log, "Unable to load module instance during ajax call")
|
||||
if 'text/html' in request.accepted_types:
|
||||
return render_to_response("module-error.html", {})
|
||||
else:
|
||||
response = HttpResponse(json.dumps({'success': "We're sorry, this module is temporarily unavailable. Our staff is working to fix it as soon as possible"}))
|
||||
return response
|
||||
|
||||
# Let the module handle the AJAX
|
||||
|
||||
@@ -226,6 +226,7 @@ TEMPLATE_LOADERS = (
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'util.middleware.ExceptionLoggingMiddleware',
|
||||
'util.middleware.AcceptMiddleware',
|
||||
'django.middleware.cache.UpdateCacheMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
|
||||
@@ -13,3 +13,30 @@ class ExceptionLoggingMiddleware(object):
|
||||
def process_exception(self, request, exception):
|
||||
log.exception(exception)
|
||||
return HttpResponseServerError("Server Error - Please try again later.")
|
||||
|
||||
# From http://djangosnippets.org/snippets/1042/
|
||||
def parse_accept_header(accept):
|
||||
"""Parse the Accept header *accept*, returning a list with pairs of
|
||||
(media_type, q_value), ordered by q values.
|
||||
"""
|
||||
result = []
|
||||
for media_range in accept.split(","):
|
||||
parts = media_range.split(";")
|
||||
media_type = parts.pop(0)
|
||||
media_params = []
|
||||
q = 1.0
|
||||
for part in parts:
|
||||
(key, value) = part.lstrip().split("=", 1)
|
||||
if key == "q":
|
||||
q = float(value)
|
||||
else:
|
||||
media_params.append((key, value))
|
||||
result.append((media_type, tuple(media_params), q))
|
||||
result.sort(lambda x, y: -cmp(x[2], y[2]))
|
||||
return result
|
||||
|
||||
class AcceptMiddleware(object):
|
||||
def process_request(self, request):
|
||||
accept = parse_accept_header(request.META.get("HTTP_ACCEPT", ""))
|
||||
request.accept = accept
|
||||
request.accepted_types = map(lambda (t, p, q): t, accept)
|
||||
|
||||
@@ -140,6 +140,7 @@ TEMPLATE_LOADERS = (
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'util.middleware.ExceptionLoggingMiddleware',
|
||||
'util.middleware.AcceptMiddleware',
|
||||
'django.middleware.cache.UpdateCacheMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
|
||||
@@ -2,43 +2,11 @@
|
||||
<%block name="bodyclass">courseware</%block>
|
||||
<%block name="title"><title>Courseware – MITx 6.002x</title></%block>
|
||||
|
||||
<%block name="headextra">
|
||||
<script type="text/javascript" src="/static/js/flot/jquery.flot.js"></script>
|
||||
</%block>
|
||||
|
||||
<%block name="js_extra">
|
||||
##Is there a reason this isn't in header_extra? Is it important that the javascript is at the bottom of the generated document?
|
||||
<!-- TODO: http://docs.jquery.com/Plugins/Validation -->
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
${init}
|
||||
|
||||
$(".sequence-nav li a").hover(function(){
|
||||
$(this).siblings().toggleClass("shown");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</%block>
|
||||
|
||||
<%include file="navigation.html" args="active_page='courseware'" />
|
||||
|
||||
<section class="main-content">
|
||||
<div class="course-wrapper">
|
||||
<section class="course-index">
|
||||
<header id="open_close_accordion">
|
||||
<h2>Courseware Index</h2>
|
||||
<a href="#">close</a>
|
||||
</header>
|
||||
|
||||
<div id="accordion">
|
||||
<nav>
|
||||
${accordion}
|
||||
</nav>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="course-content">
|
||||
${content}
|
||||
</section>
|
||||
</div>
|
||||
<section class="outside-app">
|
||||
<h1>There has been an error on the <em>MITx</em> servers</h1>
|
||||
<p>We're sorry, this module is temporarily unavailable. Our staff is working to fix it as soon as possible. Please email us at <a href="mailto:technical@mitx.mit.edu">technical@mitx.mit.edu</a> to report any problems or downtime.</p>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user