222
221
logging.debug('Logging Unhandled Exception')
224
# We handle 3 types of error.
225
# IVLEErrors with 4xx response codes (client error).
226
# IVLEErrors with 5xx response codes (handled server error).
227
# Other exceptions (unhandled server error).
228
# IVLEErrors should not have other response codes than 4xx or 5xx
229
# (eg. throw_redirect should have been used for 3xx codes).
230
# Therefore, that is treated as an unhandled error.
232
if (exc_type == util.IVLEError and httpcode >= 400
233
and httpcode <= 499):
234
# IVLEErrors with 4xx response codes are client errors.
235
# Therefore, these have a "nice" response (we even coat it in the IVLE
238
req.write_html_head_foot = True
239
req.write_javascript_settings = False
240
req.write('<div id="ivle_padding">\n')
223
# A "bad" error message. We shouldn't get here unless IVLE
224
# misbehaves (which is currently very easy, if things aren't set up
226
# Write the traceback.
227
# If this is a non-4xx IVLEError, get the message and httpcode and
228
# make the error message a bit nicer (but still include the
230
# We also need to special-case IVLEJailError, as we can get another
231
# almost-exception out of it.
233
codename, msg = None, None
235
if exc_type is util.IVLEJailError:
236
msg = exc_value.type_str + ": " + exc_value.message
237
tb = 'Exception information extracted from IVLEJailError:\n'
238
tb += urllib.unquote(exc_value.info)
242
241
codename, msg = req.get_http_codename(httpcode)
243
242
except AttributeError:
244
codename, msg = None, None
245
244
# Override the default message with the supplied one,
247
if exc_value.message is not None:
246
if hasattr(exc_value, 'message') and exc_value.message is not None:
248
247
msg = exc_value.message
249
if codename is not None:
250
req.write("<h1>Error: %s</h1>\n" % cgi.escape(codename))
252
req.write("<h1>Error</h1>\n")
254
req.write("<p>%s</p>\n" % cgi.escape(msg))
256
req.write("<p>An unknown error occured.</p>\n")
259
logging.info(str(msg))
261
req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
263
req.write("<p>Warning: Could not open Error Log: '%s'</p>\n"
264
%cgi.escape(logfile))
265
req.write('</div>\n')
266
html.write_html_foot(req)
268
# A "bad" error message. We shouldn't get here unless IVLE
269
# misbehaves (which is currently very easy, if things aren't set up
271
# Write the traceback.
272
# If this is a non-4xx IVLEError, get the message and httpcode and
273
# make the error message a bit nicer (but still include the
275
# We also need to special-case IVLEJailError, as we can get another
276
# almost-exception out of it.
278
codename, msg = None, None
280
if exc_type is util.IVLEJailError:
281
msg = exc_value.type_str + ": " + exc_value.message
282
tb = 'Exception information extracted from IVLEJailError:\n'
283
tb += urllib.unquote(exc_value.info)
286
codename, msg = req.get_http_codename(httpcode)
287
except AttributeError:
289
# Override the default message with the supplied one,
291
if hasattr(exc_value, 'message') and exc_value.message is not None:
292
msg = exc_value.message
293
# Prepend the exception type
294
if exc_type != util.IVLEError:
295
msg = exc_type.__name__ + ": " + repr(msg)
297
tb = ''.join(traceback.format_exception(exc_type, exc_value,
301
logging.error('%s\n%s'%(str(msg), tb))
302
# Error messages are only displayed is the user is NOT a student,
303
# or if there has been a problem logging the error message
304
show_errors = (not publicmode) and ((login and \
305
str(role) != "student") or logfail)
306
req.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
248
# Prepend the exception type
249
if exc_type != util.IVLEError:
250
msg = exc_type.__name__ + ": " + repr(msg)
252
tb = ''.join(traceback.format_exception(exc_type, exc_value,
256
logging.error('%s\n%s'%(str(msg), tb))
257
# Error messages are only displayed is the user is NOT a student,
258
# or if there has been a problem logging the error message
259
show_errors = (not publicmode) and ((login and \
260
str(role) != "student") or logfail)
261
req.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
307
262
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
308
263
<html xmlns="http://www.w3.org/1999/xhtml">
309
264
<head><title>IVLE Internal Server Error</title></head>
311
266
<h1>IVLE Internal Server Error""")
313
if (codename is not None
314
and httpcode != mod_python.apache.HTTP_INTERNAL_SERVER_ERROR):
315
req.write(": %s" % cgi.escape(codename))
268
if (codename is not None
269
and httpcode != mod_python.apache.HTTP_INTERNAL_SERVER_ERROR):
270
req.write(": %s" % cgi.escape(codename))
318
273
<p>An error has occured which is the fault of the IVLE developers or
319
274
administration. The developers have been notified.</p>
323
req.write("<p>%s</p>\n" % cgi.escape(msg))
324
if httpcode is not None:
325
req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
327
<p>Please report this to <a href="mailto:%s">%s</a> (the system
328
administrator). Include the following information:</p>
329
""" % (cgi.escape(admin_email), cgi.escape(admin_email)))
278
req.write("<p>%s</p>\n" % cgi.escape(msg))
279
if httpcode is not None:
280
req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
282
<p>Please report this to <a href="mailto:%s">%s</a> (the system
283
administrator). Include the following information:</p>
284
""" % (cgi.escape(admin_email), cgi.escape(admin_email)))
331
req.write("<pre>\n%s\n</pre>\n"%cgi.escape(tb))
333
req.write("<p>Warning: Could not open Error Log: '%s'</p>\n"
334
%cgi.escape(logfile))
335
req.write("</body></html>")
286
req.write("<pre>\n%s\n</pre>\n"%cgi.escape(tb))
288
req.write("<p>Warning: Could not open Error Log: '%s'</p>\n"
289
%cgi.escape(logfile))
290
req.write("</body></html>")